| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求大神帮助,本地没问题,提交结果WA。。。贴代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LEN 100
int main()
{
char morse[4*LEN+1];
int lens[LEN+1];
char out[LEN+1];
int suites;
int i, j, k;
char c;
char MORSE_TABLE[][30] = {
".-", "-...", "-.-.", "-..", ".",
"..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---",
".--.", "--.-", ".-.", "...", "-",
"..-", "...-", ".--", "-..-", "-.--",
"--..", "..--", ".-.-", "---.", "----"
};
scanf("%d", &suites);
c = getchar();
for(i=0; i<suites; i++)
{
memset(morse, 0, 4*LEN+1);
memset(out, 0, LEN+1);
j = 0;
while((c = getchar()) != '\n') {
if(c == '_') { // underscore
strcat(morse, MORSE_TABLE[26]);
lens[j++] = strlen(MORSE_TABLE[26]);
} else if (c == ',') { // comma
strcat(morse, MORSE_TABLE[27]);
lens[j++] = strlen(MORSE_TABLE[27]);
} else if (c == '.') { // period
strcat(morse, MORSE_TABLE[28]);
lens[j++] = strlen(MORSE_TABLE[28]);
} else if (c == '?') { // question mark
strcat(morse, MORSE_TABLE[29]);
lens[j++] = strlen(MORSE_TABLE[29]);
} else { // character A-Z
strcat(morse, MORSE_TABLE[c-'A']);
lens[j++] = strlen(MORSE_TABLE[c-'A']);
}
}
char code[4];
char *p = morse;
for(k = j-1; k >= 0; k--) {
memset(code, 0, 4);
strncpy(code, p, lens[k]);
p += lens[k];
int t;
for(t = 0; t < 30; t++) {
if( !strcmp(MORSE_TABLE[t], code) ) {
if(t == 26)
out[j-k-1] = '_';
else if(t == 27)
out[j-k-1] = ',';
else if(t == 28)
out[j-k-1] = '.';
else if(t == 29)
out[j-k-1] = '?';
else
out[j-k-1] = t + 'A';
}
}
}
out[j] = '\0';
printf("%d: %s\n", i+1, out);
}
return 0;
}
给一些新的测试用例也可以~~先谢过~~
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator