uva 10055 uva 457 uva 494

虽说是白书的入门题,但对细节的考察,不得不令人崩溃。。。(能力还是太水了)

//  [4/6/2014 Sjm]

uva 10055:

/*
1) vice versa    单词含义: 反之亦然
2)注意!!!
unsigned int                          无符号4字节整形   0 ~ 2^32 -1  
int                                            4字节整形  - 2^31 ~ 2^31 - 1 
__int64 或 long long            64位(8字节)整形 - 2^63 ~ 2^63 - 1 
*/

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>  // 使用 long long 必有此头文件
 4 #include <cmath>
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 int main()
 9 {
10     ll a, b;
11     while (scanf("%lld %lld", &a, &b) != EOF)
12         printf("%lld
", abs(b-a));
13     return 0;
14 }


uva 457 :

/*
注意:
1)最后一个测试用例不用输出 ' '
2)最后输出时,用 空格 代替 'b'
*/

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 const int MAX_N = 42, MAX_M = 10;
 7 int ans[2][MAX_N], myrule[MAX_M], mycount;
 8 const char ch[4] = { ' ', '.', 'x', 'W' };
 9 
10 void myOutput()
11 {
12     for (int i = 1; i <= 40; i++)
13     {
14         printf("%c", ch[ans[mycount%2][i]]);
15     }
16     printf("
");
17 }
18 
19 void Solve()
20 {
21     mycount++;
22     for (; mycount <= 50; mycount++)
23     {
24         for (int i = 1; i <= 40; i++)
25         {
26             ans[mycount % 2][i] = myrule[ans[(mycount - 1) % 2][i - 1] + ans[(mycount - 1) % 2][i] + ans[(mycount - 1) % 2][i + 1]];
27         }
28         myOutput();
29     }
30 }
31 
32 int main()
33 {
34     //freopen("input.txt", "r", stdin);
35     //freopen("output.txt", "w", stdout);
36     int T;
37     scanf("%d", &T);
38     while (T--)
39     {
40         mycount = 1;
41         for (int i = 0; i < MAX_M; i++)
42             scanf("%d", &myrule[i]);
43         memset(ans, 0, sizeof(ans));
44         ans[mycount%2][20] = 1;
45         myOutput();
46         Solve();
47         if (T) printf("
");
48     }
49     return 0;
50 }


uva 494:

/*
注意:
1)两个字符之间并不一定是用 空格 进行区分,亦有可能是逗号等
2)最后一个单词需特殊考虑,可能后面没有 非字母字符,可以加上一个 非字母字符 进行判断。
3)按照 !myJudge(i-1) && myJudge(i) 判断过不掉,不知为什么(此时设 sum 初始值为 1, i 初始值为1) 
*/

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <string>
 6 using namespace std;
 7 string str;
 8 
 9 bool myJudge(int i)
10 {
11     if ((str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= 'a' && str[i] <= 'z')) return true;
12     else return false;
13 }
14 
15 int Solve()
16 {
17     int sum = 0;
18     int mylen = str.size();
19     str += ".";
20     for (int i = 0; i < mylen; i++){
21         if (myJudge(i) && !myJudge(i+1))
22             sum++;
23     }
24     return sum;
25 }
26 
27 int main()
28 {
29     //freopen("input.txt", "r", stdin);
30     //freopen("output.txt", "w", stdout);
31     while (getline(cin, str))
32         printf("%d
", Solve());
33     return 0;
34 }
原文地址:https://www.cnblogs.com/shijianming/p/4140862.html