培訓第四天


今天已經是第四天了,早上下雨了,沒錯,這預示着——

考試!!!

今天上午迎來了第一次編程考試,題目不是特別難,但涉及到了很多需要注意的知識點,也帶給自己很多教訓

印象最深刻的是

“蒟蒻蝸牛lzh掉到了一口深井底部,但是他有夢想,他一定要爬出來!!”

那個正在檢查博客的蒟(ju)(lao)李震學長,再出這么難的題就不要爬出來了(哈哈哈開玩笑不過還是謝謝你為緊張的考試帶來一些輕松)

下面是考試題目中一些需要注意的內容(嚴肅臉):

①distance:需注意三點:一是編程中沒有絕對值符號“||”,因此對於x1、x2、x3、x4的大小要分情況討論;二是開方時一定要記得加double,如double x=sqrt(double(哇啦哇啦))(或乘1.0也ok);三是一定要記得輸入對應的庫!!!(划重點)(如保留小數、開方)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<iomanip>
 4 #include<cmath>
 5 using namespace std;
 6 int main()
 7 {
 8     freopen("task.in","r",stdin);
 9     freopen("task.out","w",stdout);
10     int x1,y1,x2,y2;
11     cin>>x1>>y1>>x2>>y2;
12     double m,n;
13     m=sqrt(double(((long long)x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
14     if(x1>=x2&&y1>=y2) {n=x1-x2+y1-y2;}
15     if(x1>=x2&&y1<y2) {n=x1-x2+y2-y1;}
16     if(x1<x2&&y1>=y2) {n=x2-x1+y1-y2;}
17     if(x1<x2&&y1<y2) {n=x2-x1+y2-y1;}
18     cout<<setiosflags(ios::fixed)<<setprecision(2);
19     cout<<m<<endl;
20     cout<<n<<endl;
21     return 0;
22 }

 

②snail(憋笑臉):這個題目有一個坑,即:若蝸牛在白天剛好到達洞口或出洞口,則晚上不再下滑,因此要恰當地在for循環里插入if。此題主要考察for(或while)循環與if的靈活運用,要對此題多加注意

 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,h=0,day=0;
 9     cin>>D>>a>>b;
10     if(D>a)
11     {
12         if(a<=b)
13       {
14         cout<<"bye bye"<<endl;
15         return 0;
16       }
17         else
18         while(h<D)    
19       {
20         day++;
21         h=h+a;
22         if(h<D) h=h-b;
23       }
24         cout<<day<<endl;
25         return 0;
26     }
27         if(D<=a) cout<<1<<endl;
28 return 0;
29 }

 

③fivesort:作為附加題,這道題確實有一定的難度,我的思路是if與for循環的配合運用,然而,不會寫……就只運用了if進行運算,步驟比較繁瑣,仍需加強對這兩個知識的掌握,if和for循環真的是編程中的重頭戲

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     freopen("fivesort","r",stdin);
 7     freopen("fivesort","w",stdout);
 8     int a,b,c,d,e,temp;
 9     cin>>a>>b>>c>>d>>e;
10     if(a>b) {temp=a; a=b; b=temp;}
11     if(a>c) {temp=a; a=c; c=temp;}
12     if(a>d) {temp=a; a=d; d=temp;}
13     if(a>e) {temp=a; a=e; e=temp;}
14     if(b>c) {temp=b; b=c; c=temp;}
15     if(b>d) {temp=b; b=d; d=temp;}
16     if(b>e) {temp=b; b=e; e=temp;}
17     if(c>d) {temp=c; c=d; d=temp;}
18     if(c>e) {temp=c; c=e; e=temp;}
19     if(d>e) {temp=d; d=e; e=temp;}
20     cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
21     return 0;
22 }
 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     freopen("fivesort","r",stdin);
 7     freopen("fivesort","w",stdout);
 8     int a,b,c,d,e;
 9     cin>>a>>b>>c>>d>>e;
10     for(int i=0;i<=1000;i++)
11     {
12         if(i==a) cout<<a<<' ';
13         if(i==b) cout<<b<<' ';
14         if(i==c) cout<<c<<' ';
15         if(i==d) cout<<d<<' ';
16         if(i==e) cout<<e<<' ';
17     }
18     return 0;
19 }

④task:這道題不難,主要運用if,提交之前多檢查,注意庫有沒有正確輸入

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     freopen("task.in","r",stdin);
 7     freopen("task.out","w",stdout);
 8     int a,b;
 9     cin>>a>>b;
10     if(a+b<10) cout<<"water"<<endl;
11     if(a+b>=10&&a>b) cout<<"tree"<<endl;
12     if(a+b>=10&&a<=b) cout<<"tea"<<endl;
13     return 0;
14 }

血淋淋的教訓:

①一定要記得輸入對應的庫!!!

②每個庫各占一行,提交前仔細檢查!!!

③有時兩個不太大的數字相乘可能很大,要加long long或乘1.0,將其轉化成小數再運算!!!

考試結束后接着刷題,進一步理解了多重循環,其運算步驟大致為:運算總的循環,接着運算循環中的循環,同樣的,符合條件繼續運算,不符合條件退出循環,直至循環中的循環運算完畢,退出循環中的循環,繼續運算總的循環,若符合條件,重復以上步驟,反之退出總的循環

以下是刷到的一些有價值的題目:

①圖形輸出3:這個題目給了我一個教訓,一定要細心細心再細心,提交了好幾遍都顯示TLE,最后才發現是把“i++”打成了“i=i++”,注意:“++”“--”系列不需再賦值,否則會陷入死循環(大概吧)

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int m;
 6     cin>>m;
 7     for(int i=1;i<=m;i++)
 8     {
 9         for(int j=1;j<=m-i;j++) {cout<<' ';}
10         for(int j=1;j<=2*i-1;j++) {cout<<'*';}
11         cout<<endl;
12     }
13     return 0;
14 }

②圖形輸出4:這是一道很有意思的題目,考察你對for循環的取值掌握以及耐心,解出此題需要編出正確的循環初值及取值范圍,要有極大的耐心和對題目充分地理解,找出規律,並正確用讀入值和變量將其表示出來

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     cin>>n;
 7     for(int i=1;i<=n;i++)
 8     {
 9         for(int j=1;j<=n-i+1;j++) cout<<' ';
10         for(int k=1;k<=2*i-1;k++) cout<<i;
11         cout<<endl;
12     }
13     for(int i=1;i<=n-1;i++)
14     {
15         for(int j=i+1;j>=1;j--) cout<<' ';
16         for(int k=2*n-1;k>=2*(i+1)-1;k--) cout<<n-i;
17         cout<<endl;
18     }
19     return 0;
20 }

努力就有進步,堅持必定成功

加油!共勉!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM