poj1298 The Hardest Problem Ever ——水题

题目链接:http://poj.org/problem?id=1298

题目大意:

  字母映射。太简单了。不说了。感脚都不好意思在博客里面写……水题一次最多切3道,再多就没意思了……也没有意义……

题目思路:

  为了学习STL,用的map。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cctype>
 6 #include <set>
 7 #include <map>
 8 #include <vector>
 9 #include <stack>
10 #include <queue>
11 #include <cmath>
12 #include <algorithm>
13 #define lson l, m, rt<<1
14 #define rson m+1, r, rt<<1|1
15 using namespace std;
16 typedef long long int LL;
17 const int MAXN =  0x3f3f3f3f;
18 const int  MIN =  -0x3f3f3f3f;
19 const double eps = 1e-9;
20 const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
21   {1,1},{1,-1},{-1,-1}};
22 map<char, char> mymap;
23 string a, b, c;
24 char aa[10000];
25 int main(void){
26 #ifndef ONLINE_JUDGE
27   freopen("1298.in", "r", stdin);
28 #endif
29   for (int i = 0; i < 26; ++i){
30     if (i <= 4)
31     mymap[i+'A'] = 'A' + 21 + i;
32     else mymap[i+'A'] = i +'A'-5; 
33   }
34   while (cin >> a){
35     if (a == "ENDOFINPUT") break;
36     getchar(); gets(aa); int len = strlen(aa);
37     for (int i = 0; i < len; ++i){
38       if (isalpha(aa[i])){
39         printf("%c", mymap[aa[i]]);
40       }
41       else printf("%c", aa[i]);
42     } printf("\n");
43     cin >> b;
44   }
45 
46   return 0;
47 }

在OJ上看到了自己以前写的代码,感脚好精简~

 1 # include <stdio.h>
 2 # include <string.h>
 3 
 4 char a[201];
 5 
 6 int main(void)
 7 {
 8    char endall[] = "ENDOFINPUT"; 
 9    char start[10]; /* = "START"; */
10    char end[4];  /* = "END"; */
11    int n = 101;
12    int i;
13    char c;
14 
15    while (n--)
16    {
17      scanf("%s", start);
18      if (strcmp(start, endall) == 0)
19        break;
20      i = 0;
21      getchar();
22      while ((c = getchar()) != '\n')
23      {
24        a[i] = c;
25        i++;
26      }
27      a[i] = '\0';
28      for (i = 0; i < strlen(a); i++)
29      {
30        if (a[i] >= 'A' && a[i] <= 'E')
31          a[i] = a[i] + 21;
32        else if (a[i] >= 'F' && a[i] <= 'Z')
33          a[i] = a[i] - 5;
34      }
35      printf("%s\n", a);
36      scanf("%s", end);
37    }
38 
39   return 0;
40 }

原来自己以前的代码风格曾经这么精悍,哈哈

posted on 2013-04-19 14:18  aries__liu  阅读(230)  评论(0编辑  收藏  举报