本题将会给出
条报错信息,确切数字未知,您需要一直读入直到文件结尾;您也可以参考 牛客网在线判题系统使用帮助 获得更多的使用帮助。每条报错信息描述如下:
在一行上先输入一个长度为
的字符串
代表文件路径;随后,在同一行输入一个整数
代表行号。
文件路径的格式如题干所述,保证文件名不为空。
至多八行,每行先输出一个长度为
的字符串
,代表文件名;随后,在同一行输出错误行号、报错次数。
D:\oblemsinnowcoder 12 D:\nowcoderproblemsinnowcoder 12 D:\nowcoder\problemsinnowcoder 13 D:\oj\problemsinnowcoder 13
oblemsinnowcoder 12 2 oblemsinnowcoder 13 2
在这个样例中,这四条报错信息去除文件路径后,由于文件名长度均超过
个字符,故我们只保留最后
个字符,得到的文件名均为
。所以,我们将它们看作同一个文件,按照报错行号划分即可。
A:\aa 1 B:\b 1 C:\c 1 D:\d 1 E:\e 1 F:\f 1 G:\g 1 H:\h 1 I:\i 1 A:\aa 1
b 1 1 c 1 1 d 1 1 e 1 1 f 1 1 g 1 1 h 1 1 i 1 1
在这个样例中,第一、十条报错信息完全相同,但是我们以其第一次出现的顺序为准,在输出最后
条记录时,不包含这一报错。
D:\zwtymj\xccb\ljj\cqzlyaszjvlsjmkwoqijggmybr 645 E:\je\rzuwnjvnuz 633 C:\km\tgjwpb\gy\atl 637 F:\weioj\hadd\connsh\rwyfvzsopsuiqjnr 647 E:\ns\mfwj\wqkoki\eez 648 D:\cfmwafhhgeyawnool 649 E:\czt\opwip\osnll\c 637 G:\nt\f 633 F:\fop\ywzqaop 631 F:\yay\jc\ywzqaop 631 D:\zwtymj\xccb\ljj\cqzlyaszjvlsjmkwoqijggmybr 645
rzuwnjvnuz 633 1 atl 637 1 rwyfvzsopsuiqjnr 647 1 eez 648 1 fmwafhhgeyawnool 649 1 c 637 1 f 633 1 ywzqaop 631 2
#include <stdio.h> #include "string.h" int main() { int a, num[100][2] = {0}; char str[101] = "\0"; char tot[100][17] = {"\0"}; while (scanf("%s %d", str, &a) != EOF) { int i = 0; for(; i < 16; i++) { if(str[strlen(str) - 1 - i] != '\\') continue; else break; } int j = 0; while(i-- > 0) str[j++] = str[strlen(str) - 1 - i]; str[j] = '\0'; int k = 0; while(num[k][0] != 0) { if(strcmp(str, tot[k]) == 0 && a == num[k][0]) { num[k][1]++; a = 0; break; } k++; } if(a != 0) { strcpy(tot[k], str); num[k][0] = a; num[k][1]++; } } int i = 0; for(; i < 100; i++) { if(num[i][0] != 0) continue; else break; } int j = i - 8; if(j < 0) { j = 0; while(num[j][0] != 0) { printf("%s", tot[j]); printf(" %d ", num[j][0]); printf("%d\n", num[j][1]); j++; } return 0; } for(int i = 0; i < 8; i++) { printf("%s", tot[j + i]); printf(" %d ", num[j + i][0]); printf("%d\n", num[j + i][1]); } return 0; }
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct recode { char str[17];//最后16个字符的文件名 int num;//行号 int count;//记错次数 }recode; void getLastFileName(char path[],char tmp[]) { char* lastSlash = strrchr(path, '\\'); // 找到最后一个斜杠字符 char fileName[100] = ""; // 存储文件名,初始化为空字符串 if (lastSlash != NULL) { // 如果找到了斜杠 strcpy(fileName, lastSlash+1); // 复制斜杠后面的字符串到fileName } else { strcpy(fileName, path); // 如果没有斜杠,直接复制整个路径到fileName } int len = strlen(fileName); if (len <= 16) strcpy(tmp,fileName); else strcpy(tmp,fileName + len - 16); } int main() { recode* list[100] = { 0 }; char path[100] = { 0 };//路径 char filename[100] = { 0 };//文件名 int i = 0;//记录次数 int j = 0; int flag = 0;//重复标志 int n = 0;//行数 //初始化字符串 for (i = 0; i < 100; i++) { list[i] = (recode*)malloc(sizeof(recode)); list[i]->num = 0; list[i]->count = 0; memset(list[i]->str, 0, sizeof(list[i]->str)); } i = 0; while (scanf("%s %d", path, &n)==2)//输入:路径和行数分开 { flag = 0;//初始化重复标志 getLastFileName(path, filename);//记录文件名 for (j = 0; j < i; j++) { //重复:文件名相同且错误行数相同 if (strcmp(filename, list[j]->str) == 0 && list[j]->num ==n) { list[j]->count++; flag = 1; break; } } if (flag == 0)//不重复 { strcpy(list[i]->str, filename); list[i]->num = n; list[i]->count=1; i++;//记录次数增加 } } //错误记录少于八条则正常输出,否则输出最后八条记录 if (i < 8) { for (j = 0; j < i; j++) { printf("%s %d %d\n", list[j]->str, list[j]->num, list[j]->count); } } else { for (j = i - 8; j < i; j++) { printf("%s %d %d\n", list[j]->str, list[j]->num, list[j]->count); } } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100 typedef struct record { char str[17]; char row[4]; int num; }record; int main() { record *note[N],temp; char *str[N]; int i=-1,j,flag1,flag2,m,n,cnt=0,p,q; do { i++; str[i]=(char*)malloc(sizeof(char)*100); gets(str[i]); }while(*str[i]!='\0'); for(j=0;j<i;j++) { flag1=0;flag2=0;m=0;p=0; while(*(str[j]+m)!='\0') { if(*(str[j]+m)=='\\') { flag1=m; } else if(*(str[j]+m)==' ') { flag2=m; break; } m++; } if((flag2-flag1-1)>16) { n=flag2-16; if(j==0) { note[cnt]=(record*)malloc(sizeof(record)); while(*(str[j]+n)!=' ') { note[cnt]->str[p++]=*(str[j]+n); n++; } note[cnt]->str[p]='\0'; n++; p=0; while(*(str[j]+n)!='\0') { note[cnt]->row[p++]=*(str[j]+n); n++; } note[cnt]->row[p]='\0'; note[cnt]->num=1; cnt++; } else if(j>0) { while(*(str[j]+n)!=' ') { temp.str[p++]=*(str[j]+n); n++; } temp.str[p]='\0'; n++; p=0; while(*(str[j]+n)!='\0') { temp.row[p++]=*(str[j]+n); n++; } temp.row[p]='\0'; for(q=0;q<cnt;q++) { if(strcmp(note[q]->str,temp.str)==0&& strcmp(note[q]->row,temp.row)==0) { note[q]->num++; break; } } if(q==cnt) { note[cnt]=(record*)malloc(sizeof(record)); strcpy(note[cnt]->str,temp.str); strcpy(note[cnt]->row,temp.row); note[cnt]->num=1; cnt++; } } } else if((flag2-flag1-1)<=16) { n=flag1+1; if(j==0) { note[cnt]=(record*)malloc(sizeof(record)); while(*(str[j]+n)!=' ') { note[cnt]->str[p++]=*(str[j]+n); n++; } note[cnt]->str[p]='\0'; n++; p=0; while(*(str[j]+n)!='\0') { note[cnt]->row[p++]=*(str[j]+n); n++; } note[cnt]->row[p]='\0'; note[cnt]->num=1; cnt++; } else if(j>0) { while(*(str[j]+n)!=' ') { temp.str[p++]=*(str[j]+n); n++; } temp.str[p]='\0'; n++; p=0; while(*(str[j]+n)!='\0') { temp.row[p++]=*(str[j]+n); n++; } temp.row[p]='\0'; for(q=0;q<cnt;q++) { if(strcmp(note[q]->str,temp.str)==0&& strcmp(note[q]->row,temp.row)==0) { note[q]->num++; break; } } if(q==cnt) { note[cnt]=(record*)malloc(sizeof(record)); strcpy(note[cnt]->str,temp.str); strcpy(note[cnt]->row,temp.row); note[cnt]->num=1; cnt++; } } } } if(cnt<=8) { for(n=0;n<cnt;n++) { printf("%s %s %d\n",note[n]->str,note[n]->row,note[n]->num); } } else { for(n=cnt-8;n<cnt;n++) { printf("%s %s %d\n",note[n]->str,note[n]->row,note[n]->num); } } return 0; } //耗时巨大,虽然代码很low,但一次就通过了
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct{ char str[17]; int row; int cnt; }T_rec; typedef struct{ T_rec rec[100]; int pWrite; }T; void rec_one(T *p_rec,char *str,int row) { int i,len,flag = 1; char *p_e,*p_s; char file_name[17]; len = strlen(str); p_e = str + len - 1; p_s = p_e; while(*p_s != '\\') p_s--; len = strlen(p_s + 1); if(len > 16) { strcpy(file_name, p_s + 1 + len - 16); } else { strcpy(file_name, p_s + 1); } for(i = 0;i < p_rec->pWrite; i++) { if(strcmp(file_name,p_rec->rec[i].str) == 0 && row == p_rec->rec[i].row) { p_rec->rec[i].cnt++; flag = 0; break; } } if(flag) { strcpy(p_rec->rec[p_rec->pWrite].str, file_name); p_rec->rec[p_rec->pWrite].cnt = 1; p_rec->rec[p_rec->pWrite].row = row; p_rec->pWrite++; } } int main() { T rec; char input[101]; int row; int i,start; memset((void *)&rec,0,sizeof(rec)); while(scanf("%s %d",input,&row) != EOF) { rec_one(&rec,input,row); } if(rec.pWrite >= 8) { start = rec.pWrite - 8; } else { start = 0; } for(i = start;i < rec.pWrite; i++) { printf("%s %d %d\n",rec.rec[i].str,rec.rec[i].row,rec.rec[i].cnt); } return 0; }
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct{ char error_name[17]; int inumber; int error_count; }ErrorInfo; ErrorInfo err_info[100] = {0}; int i_errinfo_num = 0; int main() { char str[100] = {0}; int iHangNum = 0, i = 0, j = 0; while(scanf("%s %d", str, &iHangNum) != EOF) { int is_find = 0; char *ptrTag = strrchr(str, '\\'); if(ptrTag == NULL || ++ptrTag == NULL ) { continue; } int istrLen = strlen(ptrTag); // printf("ilen:%d\n", istrLen); if(istrLen > 16) { ptrTag += (istrLen - 16); } // printf("ptrTag:%s\n", ptrTag); for(i = 0; i < i_errinfo_num; i++) { if(strcmp(ptrTag, err_info[i].error_name) == 0 && iHangNum == err_info[i].inumber) { err_info[i].error_count++; is_find = 1; break; } } if(is_find == 0) { strcpy(err_info[i_errinfo_num].error_name, ptrTag); err_info[i_errinfo_num].inumber = iHangNum; err_info[i_errinfo_num].error_count = 1; i_errinfo_num++; } } // printf("i_errinfo_num:%d\n", i_errinfo_num); if(i_errinfo_num > 8) { j = i_errinfo_num - 8; } for(i = j; i < i_errinfo_num; i++) { printf("%s %d %d\n", err_info[i].error_name, err_info[i].inumber, err_info[i].error_count); } return 0; }
#include <stdio.h> #include <string.h> #define MAX 50 #define OUTMAX 8 #define FILENAMELEN 16 int main(){ char record_name[MAX][FILENAME_MAX] = {0}; int record_line[MAX] = {0}; int record_freq[MAX] = {0}; int next = 0; char file[1000]; int line; int total = 0; while (scanf("%s %d", file, &line) == 2){ int file_len = strlen(file); int count = 1; char recorded_filename[FILENAMELEN + 1]; recorded_filename[FILENAMELEN] = '\000'; while (file[file_len-count] != '\\' && count <= FILENAMELEN){ recorded_filename[FILENAMELEN - count] = file[file_len - count]; count++; } for (int i = 0; i < count; i++){ recorded_filename[i] = recorded_filename[FILENAMELEN + 1 - count + i]; } int exist = 0; for (int i = 0; i < MAX; i++){ if (strcmp(record_name[i], recorded_filename) == 0 && record_line[i] == line){ record_freq[i]++; exist = 1; break; } } if (exist == 0){ next = next % MAX; record_freq[next] = 1; record_line[next] = line; strcpy(record_name[next], recorded_filename); next++; total++; } } total = total > MAX? MAX : total; for (int i = total - OUTMAX < 0? 0:total-OUTMAX; i < total; i++){ int idx = (next + i) % total; printf("%s %d %d\n", record_name[idx], record_line[idx], record_freq[idx]); } }