Poj Solution 1317

http://poj.org/problem?id=1317

#include <iostream>
#include <cstring>
using namespace std;


char ci[1000];
char pl[1000];

int main()
{
    int k,temp,t1;
    int i;
    int len;
    while(cin>>k && k)
    {
        getchar();
        gets(ci);//输入密文

        len=strlen(ci);

        for(i=0;i<len;i++)
        {
            if(ci[i]=='.')//这两点要特判
                temp=27;
            else if(ci[i]=='_')
                temp=0;
            else
                temp=ci[i]-'_'-1;
            
            t1=(temp+i)%28;
            //密文跟明文相对应
            if(t1==0)
            {
                pl[(k*i)%len]='_';
            }
            else if(t1==27)
            {
                pl[(k*i)%len]='.';
            }
            else
            {
                pl[(k*i)%len]='a'+t1-1;
            }
        }
        pl[i]='';//
        puts(pl);
    }
    return 0;
}
											
This entry was posted in poj. Bookmark the permalink.