📄 1515.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 1515 on 2005-09-18 at 00:48:57 */
#include <stdio.h>
#include <string.h>
int main()
{
int line, num[5200][2], len;
int i, end, j, flag, temp;
char text[5200], input[81];
while(scanf("%d", &line) == 1) {
if(line == 0) {
return 0;
} else {
text[0] = 0;
while(getchar() != '\n')
;
for(i = 0; i < line; i++) {
gets(input);
strcat(text, input);
}
len = strlen(text) - 1;
for(i = 0; i < 5200; i++) {
num[i][0] = 0;
num[i][1] = i;
}
for(i = 0; i < len; i++) {
if(num[i][0] == 0) {
end = i+1;
while(end <= len) {
if(text[end] != text[i+1]) {
if(text[end] == text[i]) {
if(end < len) {
end++;
} else {
break;
}
} else {
if(end + 2 <= len) {
end += 2;
} else {
break;
}
}
} else {
if(text[end-1] != text[i]) {
if(text[end] == text[i]) {
if(end < len) {
end++;
} else {
break;
}
} else {
if(end + 2 <= len) {
end += 2;
} else {
break;
}
}
} else {
num[i][0]++;
if(end - 1 != i) {
num[end-1][0] = -1;
}
if(text[i] == text[end]) {
if(end < len) {
end++;
} else {
break;
}
} else {
if(end + 2 <= len) {
end += 2;
} else {
break;
}
}
}
}
}
}
}
for(i = 0; i < 5; i++) {
flag = 0;
for(j = len; j >= 0; j--) {
if(num[j][0] < num[j+1][0]) {
temp = num[j][0];
num[j][0] = num[j+1][0];
num[j+1][0] = temp;
temp = num[j][1];
num[j][1] = num[j+1][1];
num[j+1][1] = temp;
flag = 1;
} else if(num[j][0] == num[j+1][0]) {
if(text[num[j][1]] > text[num[j+1][1]]) {
temp = num[j][0];
num[j][0] = num[j+1][0];
num[j+1][0] = temp;
temp = num[j][1];
num[j][1] = num[j+1][1];
num[j+1][1] = temp;
flag = 1;
} else if(text[num[j][1]] == text[num[j+1][1]]) {
if(text[num[j][1]+1] > text[num[j+1][1]+1]) {
temp = num[j][0];
num[j][0] = num[j+1][0];
num[j+1][0] = temp;
temp = num[j][1];
num[j][1] = num[j+1][1];
num[j+1][1] = temp;
flag = 1;
}
}
}
}
if(flag == 0) {
break;
}
}
for(i = 0; i < 5; i++) {
if(num[i][0] > 0) {
printf("%c%c %d %.6lf\n", text[num[i][1]], text[num[i][1]+1], num[i][0], (double)num[i][0]/len);
}
}
putchar('\n');
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -