hdu ACM steps 1.3.4 hdu 2561

来源:互联网 发布:淘宝二手名表是真的吗 编辑:程序博客网 时间:2024/05/16 14:23

题目大意:
输入一串数字,输出第二小的数字

大致思路:
不需要数组保存,用一个变量存储最小的,另一个变量存储第二小是,每次输入一个数就对两个变量比较。
这里采用直接读入两个数给变量赋初值。

c:

#include<stdio.h>int main(){    int N;    scanf("%d",&N);    while(N--)    {        int M,first=1,second=1,a,b,temp;        scanf("%d",&M);        while(M--)            if(first)            {                scanf("%d",&a);                first=0;            }            else if(second)            {                scanf("%d",&b);                second=0;                if(a<b)                    temp=a,a=b,b=temp;            }            else            {                scanf("%d",&temp);                if(temp>=b&&temp<a)                    a=temp;                else if(temp<b)                    a=b,b=temp;            }        printf("%d\n",a);    }    return 0;}
0 0