AOJ 606.LOL系列之德玛短路

160

题目


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  


i evil dna tower tsixe



Sample Output  


i live and tower exist



Source  


2013年6月月赛。 from victoira


题解


提交了10遍才AC

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

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

代码


/*
By:OhYee
Github:OhYee
Email:oyohyee@oyohyee.com
*/
#include <cstdio>

using namespace std;

#define REP(n) for(int o=0;o<n;o++)

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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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};

const int maxn = 100005;
char s[maxn];

int main() {
int i = 1;//第i个单词
char c;
while((c = getchar()) != EOF) {
//如果是单词
if(c >= 'a'&&c <= 'z') {
//读入单词
s[0] = c;
int size = 1;
while(c = getchar(),c >= 'a'&&c <= 'z')
s[size++] = c;
//输出单词
if(prime[i])
REP(size)
putchar(s[size - o - 1]);
else
REP(size)
putchar(s[o]);
i++;//记录单词序号
}

if(c == '\n') {
i = 1;
}
putchar(c);
}
//putchar('\n');
return 0;
}
发布评论
  • 点击查看/关闭被识别为广告的评论