浙大ACM 1006 WA 求助

月光下的酒 2013-11-15 06:19:15
#include<stdio.h>
#include<string.h>
#define MAX 70
int main(void){
int k;
char ciphertext[MAX];
while(scanf("%d",&k)&&k!=0){
//输入
getchar();
gets(ciphertext);
int n=strlen(ciphertext);
int ciphercode[n];

int plaincode[n];
//得到密文数组
for(int i=0;i<n;i++){
if(ciphertext[i]=='_')
ciphercode[i]=0;
else if(ciphertext[i]=='.')
ciphercode[i]=27;
else ciphercode[i]=ciphertext[i]-96;
}

//得到原文代码数组
for(int i=0;i<n;i++){
int a=0;
while(a<=27){
if(ciphercode[i]==(a-i)%28||ciphercode[i]==(a-i+28)%28)
{
int x=k*i;
x=x%n;
plaincode[x]=a;
break;

}
a++;
}

}
//test
// for(int i=0;i<n;i++)
// printf("%d\n",plaincode[i]);
//test
for(int i=0;i<n;i++){
char c;
if(plaincode[i]==0)
c='_';
else if(plaincode[i]==27)
c='.';
else c=plaincode[i]+96;
putchar(c);

}
putchar('\n');


}
}
...全文
78 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
月光下的酒 2013-11-16
  • 打赏
  • 举报
回复
谢谢二楼!过了!
logiciel 2013-11-16
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<string.h> 
//改 #define MAX 70
#define MAX 71
int main(void){
  int k;
  char ciphertext[MAX];
  while(scanf("%d",&k)&&k!=0){
    //输入 
    getchar();
    gets(ciphertext);
    int n=strlen(ciphertext);
    int ciphercode[MAX];//改 int ciphercode[n];

    int plaincode[MAX];//改 int plaincode[n];
    //得到密文数组 
    for(int i=0;i<n;i++){
      if(ciphertext[i]=='_')
        ciphercode[i]=0;
      else if(ciphertext[i]=='.')
        ciphercode[i]=27;
      else ciphercode[i]=ciphertext[i]-96;
    }

    //得到原文代码数组
    for(int i=0;i<n;i++){
      /*改 
      int a=0;
      while(a<=27){
        if(ciphercode[i]==(a-i)%28||ciphercode[i]==(a-i+28)%28)
        {
          int x=k*i;
          x=x%n;
          plaincode[x]=a;
          break;

        }
        a++;
      }*/
      plaincode[k*i%n] = (ciphercode[i]+i)%28;
    } 
    //test
    //	for(int i=0;i<n;i++)
    //		printf("%d\n",plaincode[i]);
    //test
    for(int i=0;i<n;i++){
      char c;
      if(plaincode[i]==0)
        c='_';
      else if(plaincode[i]==27)
        c='.';
      else c=plaincode[i]+96;
      putchar(c);

    }
    putchar('\n');


  }
}
月光下的酒 2013-11-15
  • 打赏
  • 举报
回复
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1006

3,882

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧