标题IDE:codeblocks
标题日期:2019/11/29
标题功能:三个自定义字符串的输出
#include <iostream>
#include <cstring>
using namespace std;
void str_swap(char *s1,char *s2)
{
char *t;
strcpy(t,s1);
strcpy(s1,s2);
strcpy(s2,t);
}
int main()
{
char s[3][10];
cout<<"请输入三个字符串";
cin>>s[0]>>s[1]>>s[2];
cout<<s[0]<<'\t'<<s[1]<<'\t'<<s[2]<<endl;
if(strcmp(s[0],s[1])>0)
str_swap(s[0],s[1]);
if(strcmp(s[0],s[2])>0)
str_swap(s[0],s[2]);
if(strcmp(s[1],s[2])>0)
str_swap(s[1],s[2]);
cout<<s[0]<<'\t'<<s[1]<<'\t'<<s[2]<<endl;
return 0;
}