zoukankan      html  css  js  c++  java
  • 培训第四天

    今天已经是第四天了,早上下雨了,没错,这预示着——

    考试!!!

    今天上午迎来了第一次编程考试,题目不是特别难,但涉及到了很多需要注意的知识点,也带给自己很多教训

    印象最深刻的是

    “蒟蒻蜗牛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 }

    努力就有进步,坚持必定成功

    加油!共勉!

  • 相关阅读:
    Java自学第18天
    Java自学第二十三天
    2\8定律,大家都要加油
    C#学习之我见
    2020年8月4日Java学习日记
    2020年8月5日
    2020年8月6日Java学习日记
    2020年8月7日Java学习日记
    第七章:(1)Spring Boot启动原理
    第六章:(3)数据访问 之 整合MyBatis
  • 原文地址:https://www.cnblogs.com/zrjl/p/7257011.html
Copyright © 2011-2022 走看看