用指针将字符串从小到大排序

来源:互联网 发布:唐七 知乎 编辑:程序博客网 时间:2024/06/06 07:19
#include<cstdio>#include<iostream>#include <cmath>#include<string>#include<algorithm>#include<set>#include<queue>#include<iterator>#include<cstring>void swap(char *p, char *q){    char t[20];    strcpy(t, p);    strcpy(p, q);    strcpy(q, t);}int main(){    char str1[20], str2[20], str3[20];    printf("input three string:\n");    scanf("%s%s%s", &str1, &str2, &str3);    if(strcmp(str1, str2)) swap(str1, str2);    if(strcmp(str1, str3)) swap(str1, str3);    if(strcmp(str2, str3)) swap(str2, str3);    printf("排好序的字符串:\n");    printf("%s %s %s\n", str1, str2, str3);    getchar();    return 0;}