pta L1-077 大笨钟的心情 (15 分)
很水的一道题,但是有一些点需要注意
错误示范:
#include<bits/stdc++.h> using namespace std; int a[30]; int b[30]; int main() { //std::ios::sync_with_stdio(false); for(register int i=1;i<=24;i++) { scanf("%d",&a[i]); } int n=1; while(true) { cin>>b[n]; if(b[n]<0||b[n]>23) { break; } else { n++; } } n=n-1; for(register int i=1;i<=n;i++) { if(a[b[i]+1]>50) printf("%d Yes",a[b[i]+1]); else { printf("%d No",a[b[i]+1]); } if(i<n) printf("\n"); } return 0; }
需要注意的点是边输入边处理,但是我挺搞不懂最后一个-1输出了居然还合法???
就当是pta的bug吧
Talk is cheap. Show me the code.
1 #include<bits/stdc++.h> 2 using namespace std; 3 int a[30]; 4 int b[30]; 5 int main() 6 { 7 //std::ios::sync_with_stdio(false); 8 for(register int i=1;i<=24;i++) 9 { 10 scanf("%d",&a[i]); 11 } 12 int n=1; 13 while(true) 14 { 15 int temp; 16 cin>>temp; 17 if(temp<0||temp>23)//不满足跳了 18 break; 19 if(a[temp+1]>50)//你会发现从一开始需要加一个下标,从0则不必 20 printf("%d Yes\n",a[temp+1]); 21 else 22 { 23 printf("%d No\n",a[temp+1]); 24 } 25 } 26 return 0; 27 }
本文来自博客园,作者:江上舟摇,转载请注明原文链接:https://www.cnblogs.com/LQS-blog/p/16160307.html