【前言】
很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过;最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化。希望是成长了一点点吧。后面定期去做做题、保持青春的活力!
1、青年回炉
Problem :
Run ID | Submit Time | Judge Status | Pro.ID | Exe.Time | Exe.Memory | Code Len. | Language | Author |
9098607 | 2013-09-03 00:52:34 | Accepted | 0MS | 200K | G++ | |||
864320 | 2008-10-31 14:14:02 | Accepted | 0MS | 0K | C++ |
2、从代码中发现成长的轨迹
2.1 曾经的代码
Problem : Judge Status : AcceptedRunId : 864320 Language : C++ Author : Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#includeusing namespace std;int main(void){ int a[100],i,j,n,flag,down; long total; while(cin>>n&&n) { a[0]=total=flag=down=0; for(i=1;i<=n;i++) { cin>>a[i]; if(!down) { if(a[i]>a[i-1])continue; total+=6*(a[i-1]-a[flag]); flag=i-1;down=1; } else { if(a[i] a[n-1])total+=(a[n]-a[flag])*6; else total+=(a[flag]-a[n])*4; total+=5*n; cout< <
2.2 现在的风格
Problem : Judge Status : AcceptedRunId : 9098607 Language : G++ Author : Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#includeint main(){ int count=0; int cur_floor=0; int last_floor=0; int total_time=0; int i=0; scanf("%d", &count); while (count != 0){ total_time = 0; last_floor = 0; for (i=0; i last_floor){ total_time += 6*(cur_floor-last_floor); } else{ total_time += 4*(last_floor-cur_floor); } total_time += 5; last_floor = cur_floor; } printf("%d\n", total_time); scanf("%d", &count); } return 0;}