题目链接:http://poj.org/problem?id=1317
对题目所给运算规则的逆运算,注意取余的运算规则。
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
char dic[]="_abcdefghijklmnopqrstuvwxyz.";
char str[80];
char ans[80];
int main()
{
int k;
while(scanf("%d",&k)!=EOF&&k)
{
scanf("%s",str);
int len=strlen(str);
for(int i=0;i<len;i++)
{
int tmp;
if(str[i]=='_')
tmp=0;
else if(str[i]=='.')
tmp=27;
else
tmp=str[i]-'a'+1;
tmp+=i;
tmp%=28;
int t=k*i;
t%=len;
ans[t]=dic[tmp];
}
ans[len]='\0';
printf("%s\n",ans);
}
return 0;
}
本文提供了一道来自POJ平台的题目解题思路与代码实现。题目要求进行特定的字符串逆运算,并考虑了取余运算规则的影响。通过C++实现了解决方案,包括字符串操作和循环移位等关键技术点。
4281

被折叠的 条评论
为什么被折叠?



