HDU-2000

2023-11-17

题目本身不难,但是对于初学者,难的是数据的读入。

方法一:使用getchar()去除每一行的空格符

#include<stdio.h>
int main()
{
char a,b,c,t;
while(scanf("%c%c%c",&a,&b,&c)!=EOF)
{
getchar();                                                   //滤掉scanf的最后的回车 ,不然循环第二次输入、输出不正常
if(a>b){t=a;a=b;b=t;}
if(a>c){t=a;a=c;c=t;}
if(b>c){t=b;b=c;c=t;}
printf("%c %c %c\n",a,b,c);
}
return 0;
 } 

方法二:用%s输入到数组中

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    char a[4];
    while(scanf("%s",a)!=EOF)
    {
        sort(a,a+3);
        printf("%c %c %c\n",a[0],a[1],a[2]);
    }
    return 0;
}

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HDU-2000 的相关文章

随机推荐