不知道问题在哪儿,希望有伙伴来解答

0
0

就是基本的录入日志记录,然后记录每条日志的对应存储位置,然后按照模拟栈的操作进行,不匹配或是栈出现非空的都是不对的,然后主进程要被主进程结束;其他的想不到有什么问题

bool start[20020];

/** *根据日志信息,得到函数调用关系,以DFS的关系输出 */

int main(){

int N;
//  FILE *fin = fopen("G:\\input.txt", "r");
//  FILE *fout = fopen("G:\\data_output.txt", "w");
//  fscanf(fin, "%d", &N);
scanf("%d", &N);
vector<pair<string, int> > info(N);
vector<pair<string, int> > forJudge;//存储函数名,与其在info中的索引
for (int i = 0; i<N; i++){
    char name[256], time[10], action[8];
    //      fscanf(fin, "%s%s%s", name, time, action);
    scanf("%s%s%s", name, time, action);
    int hour, min, second;
    sscanf(time, "%d:%d:%d", &hour, &min, &second);
    int time_seconds = hour * 3600 + min * 60 + second;
    info[i] = make_pair(name, time_seconds);
    if (strcmp(action, "START") == 0){
        start[i] = true;
        forJudge.push_back(make_pair(name, i));
    }
    else{
        if (forJudge.size() == 0 || strcmp(forJudge.rbegin()->first.c_str(), name) != 0){//not matched
            // fprintf(fout, "Incorrect performance log\n");
            printf("Incorrect performance log\n");
            return 0;
        }
        if (time_seconds<info[forJudge.rbegin()->second].second){
            printf("Incorrect performance log\n");
            return 0;
        }
        info[forJudge.rbegin()->second].second = time_seconds - info[forJudge.rbegin()->second].second;
        forJudge.pop_back();
    }
}
if (forJudge.size() != 0 || info[0].first != info[N - 1].first){
    printf("Incorrect performance log\n");
    return 0;
}
for (int i = 0; i<N; i++){
    if (start[i]){
        //          fprintf(fout, "%s", info[i].first.c_str());
        printf("%s", info[i].first.c_str());
        int hour, min, second;
        hour = info[i].second / 3600;
        min = info[i].second % 3600 / 60;
        second = info[i].second % 3600;
        //          fprintf(fout, " %02d:%02d:%02d\n", hour, min, second);
        printf(" %02d:%02d:%02d\n", hour, min, second);
    }
}
system("pause");
return 0;

}

0 answer(s)

write answer 切换为英文 切换为中文


转发分享