“Crypto Columns” ACM这题总是Wrong Answer,为什么??
#include<iostream>#include<stdlib.h>#include<stdio.h>#include<string.h>usingnamespace...
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int sq[11];
char key[11];
char cip[101];
char res[101][11];
int lk = 0, lc = 0, m = 0, n = 0;
while(scanf("%s", key) == 1 && strcmp(key, "THEEND"))
{
scanf("%s", cip);
lk = strlen(key);
lc = strlen(cip);
for(int i = 0; i < lk; i++)
sq[i] = i;
for(int i = 0; i < lk; i++)
{
for(int j = i + 1; j < lk; j++)
{
if(key[i] > key[j])
{
char c = key[i];
int tmp = sq[i];
key[i] = key[j];
key[j] = c;
sq[i] = sq[j];
sq[j] = tmp;
}
}
}
m = lc*1.0 / lk + 0.5;
for(int i = 0; i < lc; i = i + m)
{
n = sq[i/m];
for(int j = 0; j < m; j++)
{
res[j][n] = cip[i + j];
res[j][lk] = '\0';
}
}
for(int i = 0; i < m; i++)
{
printf("%s", res[i]);
}
printf("\n");
}
return 0;
} 展开
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
int sq[11];
char key[11];
char cip[101];
char res[101][11];
int lk = 0, lc = 0, m = 0, n = 0;
while(scanf("%s", key) == 1 && strcmp(key, "THEEND"))
{
scanf("%s", cip);
lk = strlen(key);
lc = strlen(cip);
for(int i = 0; i < lk; i++)
sq[i] = i;
for(int i = 0; i < lk; i++)
{
for(int j = i + 1; j < lk; j++)
{
if(key[i] > key[j])
{
char c = key[i];
int tmp = sq[i];
key[i] = key[j];
key[j] = c;
sq[i] = sq[j];
sq[j] = tmp;
}
}
}
m = lc*1.0 / lk + 0.5;
for(int i = 0; i < lc; i = i + m)
{
n = sq[i/m];
for(int j = 0; j < m; j++)
{
res[j][n] = cip[i + j];
res[j][lk] = '\0';
}
}
for(int i = 0; i < m; i++)
{
printf("%s", res[i]);
}
printf("\n");
}
return 0;
} 展开
展开全部
给个题目网址吧。
更多追问追答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询