#include <iostream> #include <sstream> #include <stdio.h> #include <string> using namespace std; /*string a = "abc" ,将a放到字符数组*/ void convert(string str,char s[]) { /*abc的长度是3*/
/*string a = "abcde" char aa[]=a;不可以,char aa[]="123"可以*/ for(int i=0;i<str.size();i++){ s[i]=str[i]; } } void chuli(char a[],int N) { //3个元素2趟排序 for(int j =1;j<N;j++ ){ for(int i=0;i<N-j;i++){ if(a[i]>a[i+1]) {int temp=a[i];a[i]=a[i+1];a[i+1] =temp;} } } for(int m=0;m<3;m++) {cout<<a[m]; cout<<" ";} printf(" "); } int main() { /*动态建立2个数组*/ int num; cin>>num; char *p=new char[3]; string *str =new string[num]; /*给字符串数组赋值*/ for(int i=0;i<num;i++){ string a; cin >>a; //用c特有的scanf输入字符串不好 str[i]=a; } for(int k=0;k<num;k++){ convert(str[k],p); chuli(p,3); p[0]='