#include <algorithm>
#include <iostream> C++函数的调用
#include <cstdlib>
using namespace std;
int main(void) {
char s[4];
while (cin >> s) {
sort(s, s + 3);
cout << s[0] << ' ' << s[1] << ' ' << s[2] << endl;
}
return EXIT_SUCCESS; //等同于 return 0
}
#include<iostream>
using namespace std;
int main()
{
char a[3];
while (cin >> a)//输入字符 ,可以一直输入
{
if (a[0] > a[1]) swap(a[0], a[1]);//比较
if (a[0] > a[2]) swap(a[0], a[2]);
if (a[1] > a[2]) swap(a[1], a[2]);
cout << a[0] << " " << a[1] << " " << a[2] << endl;
}
return 0;
}
冒泡法
#include<iostream>
using namespace std;
int main()
{
char str[3];
while (cin >> str)
{
char l;
for (int n = 0; n < 2; n++)//冒泡排序
for (int i = 0; i < 2; i++)
if (str[i] > str[i + 1])
{
l = str[i];
str[i] = str[i + 1];
str[i + 1] = l;
}
for (int i = 0; i < 2; i++)
{
cout << str[i];//输出0-2,每输出1个空1下
cout << " ";
}
cout << str[2] << endl;//到str[2]换行
}
}
#include <stdio.h>
int main()
{
char a,b,c,t;
while(scanf("%c%c%c%*c",&a,&b,&c)!=EOF) //用"%*c"(空字符,不存储字符的字符)滤掉回车
{
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;
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(void) {
double x[2], y[2];
while (scanf("%lf%lf%lf%lf", x, y, x+1, y+1) != EOF) {
printf("%.2f\n", sqrt(pow(x[1] - x[0], 2) + pow(y[1] - y[0], 2)));
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
double x1,y1,x2,y2;
double z;
while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
{
z=sqrt(pow((x1-x2),2)+pow((y1-y2),2));
printf("%.2f\n",z);
}
}
#include<stdio.h>
#include<math.h>
#define P 3.1415927
int main()
{
double r,n;
while(scanf("%lf",&r)!=EOF)
{
n=4.0/3.0*P*pow(r,3);
printf("%.3f\n",n);
}
}