AOJ 606.LOL系列之德玛短路

Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
Total Submission: 215   Submission Accepted: 79
 
Description
德玛的经典台词:人在塔在。由于最近LOL增加了草丛数量(草丛伦怎能不开心?!)由于太过于兴奋,盖伦突然变成白痴了- -,连最经典的台词都变为:人在塔亡(变身剑圣?),德玛现在的症状是:如果该单词在句子中的序号为素数的话,他就会把这个单词反过来说(abcd -> dcba),为了治疗盖伦,你得和盖伦交流,寻求找到治疗他的方法。德玛说话完全变反了,现在你的任务是将盖伦的话翻译回他本来的意思,比如德玛说:i evil dna tower tsixe其实他的本意是i live and tower exist(因为2,3,5是素数,所以这些位置上的单词反过来了)
注意:1不是素数,而且可能会有许多多余的空格!

 

Input
输入包括多组测试数据,以文件(EOF)结束
每行一个字符串,由小写字母和空格组成(最多不会超过500个单词,字符串总长度不超过10^5)

 

Output
输出每个字符串对应的原意

 

Sample Input
Original Transformed
i evil   dna tower tsixe

 

Sample Output
Original Transformed
i live   and tower exist

 

Source
2013年6月月赛。 from victoira

提交了10遍才AC

其中要注意对于每一个不是单词的字符,都要如实在输出,对于是单词的字符,按照要求输出。

要判断一个数是否是素数,打表或者用筛法

 1 /*
 2 By:OhYee
 3 Github:OhYee
 4 Email:oyohyee@oyohyee.com
 5 */
 6 #include <cstdio>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <cmath>
10 #include <string>
11 #include <iostream>
12 #include <vector>
13 #include <list>
14 #include <stack>
15 using namespace std;
16  
17 #define REP(n) for(int o=0;o<n;o++)
18  
19 const bool prime[] = {0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,
20 0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,
21 0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,
22 0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,
23 1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,
24 0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,
25 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,
26 0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,
27 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,
28 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,
29 1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,
30 0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,
31 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,
32 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0};
33  
34 const int maxn = 100005;
35 char s[maxn];
36  
37 int main() {
38     int i = 1;//第i个单词
39     char c;
40     while((c = getchar()) != EOF) {
41         //如果是单词
42         if(c >= 'a'&&c <= 'z') {
43             //读入单词
44             s[0] = c;
45             int size = 1;
46             while(c = getchar(),c >= 'a'&&c <= 'z')
47                 s[size++] = c;
48             //输出单词
49             if(prime[i])
50                 REP(size)
51                 putchar(s[size - o - 1]);
52             else
53                 REP(size)
54                 putchar(s[o]);
55             i++;//记录单词序号
56         }
57  
58         if(c == '\n') {
59             i = 1;
60         }
61         putchar(c);
62     }
63     //putchar('\n');
64     return 0;
65 }

 

posted @ 2016-03-12 20:06  OhYee  阅读(269)  评论(0编辑  收藏  举报