学长,请您看一下这篇我史上最走心博客:
注:以上是我在“记事本”里写的发现复制不了,只好剪切了,但是特走心。
上午的考试最最最最最最最最亏的一道题就是呢个distance。我少了一个库(#include<cmath>)啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊抓狂,就这样就错了,生无可恋!!!
正确的答案如下:
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath>(LWS啊,你可长点心吧) 4 #include<iomanip> 5 using namespace std; 6 int main() 7 { 8 freopen("distance.in","r",stdin); 9 freopen("distance.out","w",stdout); 10 cout<<setiosflags(ios::fixed)<<setprecision(2); 11 int xx1,xx2,yy1,yy2; 12 cin>>xx1>>yy1>>xx2>>yy2; 13 double c,d,e,f; 14 c=sqrt(1.0*(xx1-xx2)*(xx1-xx2)+1.0*(yy1-yy2)*(yy1-yy2)); 15 if(xx1<xx2) 16 d=xx2-xx1; 17 else 18 d=xx1-xx2; 19 if(yy1<yy2) 20 e=yy2-yy1; 21 else 22 e=yy1-yy2; 23 f=d+e; 24 cout<<c<<endl<<f<<endl; 25 return 0; 26 }
另一道错题就是学长的佳作“snail”这道题我考虑的不全面,理应感受痛苦。正确答案如下:
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int main() 5 { 6 freopen("snail.in","r",stdin); 7 freopen("snail.out","w",stdout); 8 int D,a,b,x=0;//x是计数器 9 cin>>D>>a>>b; 10 if(a<=b&&D>a) 11 cout<<"bye bye"<<endl; 12 else 13 { 14 for(;;)//无条件循环 15 { 16 x++; 17 D-=a; 18 if(D<=0) 19 break;//跳出程序,否则死循环 20 D+=b; 21 } 22 cout<<x<<endl; 23 } 24 return 0; 25 }
这道题需要考虑一天就爬上的可能性和不整除的可能性,这些我都忽略了。。。无语呀。。。
fivesort这道题我虽然写对了,但用的是书上的方法,个人感觉没有另一种方法简洁,仍需学习啊。另一种方法如下:
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int main() 5 { 6 freopen("fivesort.in","r",stdin); 7 freopen("fivesort.out","w",stdout); 8 int a,b,c,d,e; 9 cin>>a>>b>>c>>d>>e; 10 for(int i=1;i<=1000;i++) 11 { 12 if(i==a) 13 cout<<a<<' '; 14 if(i==b) 15 cout<<b<<' '; 16 if(i==c) 17 cout<<c<<' '; 18 if(i==d) 19 cout<<d<<' '; 20 if(i==e) 21 cout<<e<<' '; 22 } 23 return 0; 24 }
上午的考试收获还是蛮多的。我不但掌握了更多的方法逻辑、知道了自己容易犯的错误,还发现计算机是比较严谨的,像我居然漏了一个库导致整题0分的情况实则不该。