poj1298 The Hardest Problem Ever ——水题

April 19, 2013
POJ

题目链接:http://poj.org/problem?id=1298 题目大意:   字母映射。太简单了。不说了。感脚都不好意思在博客里面写……水题一次最多切3道,再多就没意思了……也没有意义…… 题目思路:   为了学习STL,用的map。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long int LL;
const int MAXN =  0x3f3f3f3f;
const int  MIN =  -0x3f3f3f3f;
const double eps = 1e-9;
const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
  {1,1},{1,-1},{-1,-1}};
map<char, char> mymap;
string a, b, c;
char aa[10000];
int main(void){
#ifndef ONLINE_JUDGE
  freopen("1298.in", "r", stdin);
#endif
  for (int i = 0; i < 26; ++i){
    if (i <= 4)
    mymap[i+'A'] = 'A' + 21 + i;
    else mymap[i+'A'] = i +'A'-5; 
  }
  while (cin >> a){
    if (a == "ENDOFINPUT") break;
    getchar(); gets(aa); int len = strlen(aa);
    for (int i = 0; i < len; ++i){
      if (isalpha(aa[i])){
        printf("%c", mymap[aa[i]]);
      }
      else printf("%c", aa[i]);
    } printf("\n");
    cin >> b;
  }

  return 0;
}

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


# include <stdio.h>
# include <string.h>

char a[201];

int main(void)
{
   char endall[] = "ENDOFINPUT"; 
   char start[10]; /* = "START"; */
   char end[4];  /* = "END"; */
   int n = 101;
   int i;
   char c;

   while (n--)
   {
     scanf("%s", start);
     if (strcmp(start, endall) == 0)
       break;
     i = 0;
     getchar();
     while ((c = getchar()) != '\n')
     {
       a[i] = c;
       i++;
     }
     a[i] = '\0';
     for (i = 0; i < strlen(a); i++)
     {
       if (a[i] >= 'A' && a[i] <= 'E')
         a[i] = a[i] + 21;
       else if (a[i] >= 'F' && a[i] <= 'Z')
         a[i] = a[i] - 5;
     }
     printf("%s\n", a);
     scanf("%s", end);
   }

  return 0;
}

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

comments powered by Disqus