zoukankan      html  css  js  c++  java
  • 团体程序设计天梯赛 L1-010. 比较大小

    测试数据:

    1 2 3

    1 3 2

    2 1 3

    2 3 1

    3 1 2

    3 2 1

    Code:

    先确定最小,然后确定第二小

     1 #include <stdio.h> 
     2 #include <stdlib.h>
     3 
     4 int main()
     5 {
     6     long t,a,b,c;
     7     scanf("%ld%ld%ld",&a,&b,&c);
     8     if (a>b)
     9     {
    10         t=a;
    11         a=b;
    12         b=t;
    13     }
    14     if (a>c)
    15     {
    16         t=a;
    17         a=c;
    18         c=t;
    19     }
    20     if (b>c)
    21     {
    22         t=b;
    23         b=c;
    24         c=t;
    25     }
    26     printf("%ld->%ld->%ld",a,b,c);
    27     return 0;
    28 }

    一个比较坑的错误程序:

     1 #include <stdio.h> 
     2 #include <stdlib.h>
     3 
     4 int main()
     5 {
     6     long t,a,b,c;
     7     scanf("%ld%ld%ld",&a,&b,&c);
     8     if (a>b)
     9     {
    10         t=a;
    11         a=b;
    12         b=t;
    13     }
    14     if (b>c)
    15     {
    16         t=b;
    17         b=c;
    18         c=t;
    19     }
    20     if (a>c)
    21     {
    22         t=a;
    23         a=c;
    24         c=t;
    25     }
    26     printf("%ld->%ld->%ld",a,b,c);
    27     return 0;
    28 }

    错误结果:

    2 3 1
    2->1->3

    3 2 1
    2->1->3

  • 相关阅读:
    c# 线程同步各类锁
    C#_从DataTable中检索信息
    永无BUG
    标志枚举
    将多行按分隔符"|"合成一行
    回车换行浅析
    url传输编码
    xshell 禁用铃声 提示音
    php 编译安装 mysql.so
    301 302 304
  • 原文地址:https://www.cnblogs.com/cmyg/p/8574572.html
Copyright © 2011-2022 走看看