还有7/8/10这三个点过不了啊

#include<stdio.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
typedef struct Decipher{
    char cipher[10000];
    char decipher[3][10000];
}Decipher;
Decipher cipher[3];
int main() {
    int n,i,j,k,other,another,k2,flag;
    freopen("Text.txt","r",stdin);
    scanf("%d %s %s %s",&n,cipher[0].cipher,cipher[1].cipher,cipher[2].cipher);
    for(k = 0; k <= 6; k++) {
        for(k2 = 0; k2 <= 6; k2++) {
            for(i = 0; i < 3; i++) {
                for(j = 0; j < n; j++) {
                    cipher[i].decipher[0][j] = cipher[i].cipher[n-j-1];
                    if((cipher[i].cipher[j] + k)>'z')
                        cipher[i].decipher[1][j] = (cipher[i].cipher[j] + k) % 'z' + 'a'-1;
                    else cipher[i].decipher[1][j] = (cipher[i].cipher[j] + k);

                    if((cipher[i].cipher[j] - k2)<'a')
                        cipher[i].decipher[2][j] = 'z'-('a'-(cipher[i].cipher[j] - k2))+1;
                    else cipher[i].decipher[2][j] = (cipher[i].cipher[j] - k2);
                }
            }
            //三个都是aba的情况
            flag = 0;
            for(i = 0; i < 3; i++) {
                other = (i==0?1:0);
                another = (i==2?1:2);
                if(strcmp(cipher[0].decipher[i],cipher[1].decipher[other]) == 0) {
                    if(strcmp(cipher[0].decipher[i],cipher[2].decipher[another]) == 0) {
                        if(!flag) printf("%s\n",cipher[0].decipher[i]);
                        flag = 1;
                    }
                }
                if(strcmp(cipher[0].decipher[i],cipher[1].decipher[another]) == 0) {
                    if(strcmp(cipher[0].decipher[i],cipher[2].decipher[other]) == 0) {
                        if(!flag) printf("%s\n",cipher[0].decipher[i]);
                        flag = 1;
                    }
                }
            }
        }
    }
    return 0;
}

1 条评论

  • @ 2018-03-11 19:32:34

    字符串长度应该+1,题目给的限定范围是 <= 10000
    char 的长度应该设置为 10001

  • 1

信息

ID
1449
难度
6
分类
字符串 | 模拟 点击显示
标签
递交数
6976
已通过
1870
通过率
27%
被复制
9
上传者