[HDU] [2000] ASCII Code Sorting

Problem Description

Loading...

Problem Analysis

A very simple three-letter sort
I struggled with it for a while because of that
\n buffer problem
You can solve it by creating an extra variable
But after looking into it a bit more
using getchar() is an even better solution

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
int main() {
	char x,y,z,t;
	while(scanf("%c%c%c",&x,&y,&z)!=EOF) {
		getchar();
		if(x>y) {
			t=x;
			x=y;
			y=t;
		}
		if(y>z) {
			t=y;
			y=z;
			z=t;
		}
		if(x>y) {
			t=x;
			x=y;
			y=t;
		}
		printf("%c %c %c\n",x,y,z);
	}
	return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...