20191116-SWITCH

  1. #include "stdafx.h" 

  2.  #include "cstdio" 

  3.  #include "iostream" 

  4.  using namespace std; 

  5.  int main(){ 

  6.     int a,b,c,d;

  7.     cin>>a>>b>>c>>d;

  8.     int m=a;

  9.     if(m>b)

  10.        m=b;

  11.     if(m>c)

  12.       m=c;

  13.     if(m>d)

  14.      m=d;

  15.      cout<<m<<endl;}

  16. 这是解法1,运行结果如下:

  17.  

  18.  

  19.  

  20.  

  21. #include "stdafx.h" 

  22.  #include "cstdio" 

  23.  #include "iostream" 

  24.  using namespace std; 

  25.  int main(){ 

  26.     int a,b,c,d;

  27.     cin>>a>>b>>c>>d;

  28.     int m=a;

  29.     if(m>b)

  30.        m=b;

  31.     if(m>c)

  32.       m=c;

  33.     if(m>d)

  34.      m=d;

  35.       cout<<m<<endl;}

    1. 这是解法2,运行结果如下:

        

      

  36.  

    1. #include "stdafx.h" 

    2.  #include "cstdio" 

    3.  #include "iostream" 

    4. #include "algorithm"//sort 

    5.  using namespace std; 

    6. int e[4];

    7.  int main(){ 

    8.     int a,b,c,d;

    9.     cin>>a>>b>>c>>d;

    10.     e[0]=a;e[1]=b;e[2]=c;e[3]=d;

    11.     sort(e,e+4);

    12.      cout<<e[0]<<endl;}

    13. 这是解法3,运行结果如下:

       

      

      

     

      

 

posted @ 2020-05-21 08:00  财盛  阅读(95)  评论(0编辑  收藏  举报