#1057 : Performance Log 线程日志(栈模拟)
来源:互联网 发布:淘宝修改密码网址 编辑:程序博客网 时间:2024/05/29 12:26
Link:http://hihocoder.com/problemset/problem/1057#
- 样例输入
8FuncA 00:00:01 STARTFuncB 00:00:02 STARTFuncC 00:00:03 STARTFuncC 00:00:04 ENDFuncB 00:00:05 ENDFuncD 00:00:06 STARTFuncD 00:00:07 ENDFuncA 00:00:08 END
- 样例输出
FuncA 00:00:07FuncB 00:00:03FuncC 00:00:01FuncD 00:00:01
描述
You are given a txt file, which is performance logs of a single-threaded program.
Each line has three columns as follow:
[Function Name] [TimeStamp] [Action]
[FunctionName] is a string of length between 1~255
[TimeStamp] format is hh:mm:ss
Valid values for "Action" column are START or END, marking the start or end of a function call.
Each function will only be called once.
Output the depth-first traversal result of the call graph with the total time of each function call. However, sometimes the performance log isn't correct and at that time you just need to output "Incorrect performance log".
输入
The input only contains 1 case, first line is a positive number N representing the number of logs(1 <= N <= 20000), then there are N lines in next, each line is the log info containing [Function Name] [TimeStamp] [Action], [Function Name] is a string, you can assume the [Function Name] is distinct and the length between 1~255.
输出
Output the depth-first traversal result of the call graph with the total time of each function call for the correct performance, or output "Incorrect performance log".
提示
A call graph is a directed graph that represents calling relationships between subroutines in a computer program.
Call graph for the sample input is shown as below:
Another sample test case.
Sample InputSample Output8FuncA 00:00:01 START
FuncB 00:00:02 START
FuncC 00:00:03 START
FuncA 00:00:04 END
FuncB 00:00:05 END
FuncD 00:00:06 START
FuncD 00:00:07 END
FuncC 00:00:08 ENDIncorrect performance log
AC code:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#include<queue>#include<map>#include<stack>#include<vector>#define LL long long#define MAXN 100010using namespace std;int n;string fun[20002];int hh[20002][2],mm[20002][2],ss[20002][2]; int th[20002],tm[20002],ts[20002]; int sss[20002][2];int sta[20002],vis[20002];int top,fg,cnt,pre;map<string,int>id;int main(){//freopen("D:\\in.txt","r",stdin);string s1,s2;int i,h,m,s;while(scanf("%d",&n)!=EOF){//map<string,int>id;id.clear();top=0;fg=1;cnt=0;for(i=1;i<=n;i++){cin>>s1;scanf("%d:%d:%d",&h,&m,&s);cin>>s2;if(s2=="START"){if(id[s1]!=0){fg=0;}fun[++cnt]=s1;hh[cnt][0]=h;mm[cnt][0]=m;ss[cnt][0]=s;id[s1]=cnt;sta[++top]=cnt;sss[cnt][0]=h*3600+m*60+s;if(i!=1){if(pre>sss[cnt][0]){fg=0;}}pre=sss[cnt][0];}else if(s2=="END"){if(id[s1]==0){fg=0;}if(top==0||sta[top]!=id[s1]){fg=0;}else{hh[id[s1]][1]=h;mm[id[s1]][1]=m;ss[id[s1]][1]=s;sss[id[s1]][1]=h*3600+m*60+s;if(i!=1){if(pre>sss[id[s1]][1]){fg=0;}}pre=sss[id[s1]][1];if(sss[id[s1]][1]<sss[id[s1]][0]){fg=0;}else{int ssss=sss[id[s1]][1]-sss[id[s1]][0];th[id[s1]]=ssss/3600;ssss-=th[id[s1]]*3600;tm[id[s1]]=ssss/60;ssss-=tm[id[s1]]*60;ts[id[s1]]=ssss;}if(top==0){fg=0;}else{top--;}}}}if(!fg){printf("Incorrect performance log\n");}else{for(i=1;i<=cnt;i++){cout<<fun[i]<<" ";if(th[i]<10){printf("0%d:",th[i]);}else{printf("%d:",th[i]);}if(tm[i]<10){printf("0%d:",tm[i]);}else{printf("%d:",tm[i]);}if(ts[i]<10){printf("0%d\n",ts[i]);}else{printf("%d\n",ts[i]);}}}} return 0;}
- #1057 : Performance Log 线程日志(栈模拟)
- hihocoder 1057 : Performance Log
- hihocoder 1057 : Performance Log
- hihoCoder #1057 : Performance Log
- Performance Log
- C# 实现记录每个线程log日志
- 日志(log)相关
- 【hihocoder】 Performance Log
- log日志:简单的log日志输出(C++)
- 全栈必备 Log日志
- 全栈必备 Log日志
- Android Log 日志调试(打印日志)
- 日志处理类(Log)
- Log日志系统(一)
- Log日志规范(转)
- (2) 配置日志log
- Android日志(Log类)
- Tomcat日志log(转载)
- 查看服务器日志相关
- 图
- Cannot create JDBC driver of class '' for connect URL 'null’
- Http协议讲义及相应过程
- *LeetCode-Rotate Image
- #1057 : Performance Log 线程日志(栈模拟)
- java正则表达式
- servlet内置对象
- JSP编码以及乱码解决总结
- 作用域
- CentOS 6下Nvidia显卡驱动程序的安装整理总结
- poj1106Transmitters【求旋转半圆能覆盖的最多点数】
- EmguCV录制视频
- 一 JavaScript概述