题解 | #简单错误记录#
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <stdio.h>
#include <string.h>
static char g_input[100][17] = {0};
static int g_num[100][2] = {0}; /* 0 为输入行号,1 为统计数次数 */
int main(int argc, char** argv)
{
int num = 0, len = 0;
char tmp[101], *str;
while (scanf("%s%d", tmp, &g_num[num][0]) != EOF) {
str = strrchr(tmp, '\\') + 1;
len = strlen(str);
if (len > 16) str += len - 16;
memcpy(g_input[num], str, strlen(str) + 1);
num++;
}
for (int i = 0; i < num; i++) {
g_num[i][1] = 1;
for (int j = i + 1; j < num; j++) {
if ((strcmp(g_input[i], g_input[j]) == 0) && (g_num[i][0] == g_num[j][0])) {
for (int k = j + 1; k < num; k++) {
memcpy(g_input[k - 1], g_input[k], strlen(g_input[k]) + 1);
g_num[k - 1][0] = g_num[k][0];
}
g_num[i][1]++; num--; j--;
}
}
}
for (int i = ((0 > (num - 8)) ? 0 : (num - 8)); i < num; i++) printf("%s %d %d\n", g_input[i], g_num[i][0], g_num[i][1]);
return 0;
}