1 solutions
-
0
C++ :
#include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> using namespace std; int check(char a[],char b[]); int main() { char str[21][101]; char temp[100]; int n,i,j; cin>>n; for(i=0;i<n;i++) cin>>str[i]; for(i=0;i<n-1;i++) for(j=n-1;j>i;j--) { if(strcmp(str[j-1],str[j])<0) { strcpy(temp,str[j]); strcpy(str[j],str[j-1]); strcpy(str[j-1],temp); } if(strcmp(str[j-1],str[j])>0&&check(str[j-1],str[j])) { strcpy(temp,str[j]); strcpy(str[j],str[j-1]); strcpy(str[j-1],temp); } } for(i=0;i<n;i++) cout<<str[i]; //system("pause"); return 0; } int check(char a[],char b[]) { char s1[100],s2[100]; strcpy(s1,a); strcpy(s2,b); strcat(s1,b); strcat(s2,a); if(strcmp(s1,s2)>0) return 0; else return 1; }
Pascal :
var s:array[1..20] of string; t:string;i,j,k,n:longint; begin readln(n); for i:=1 to n do begin read(k); str(k,s[i]); end; for i:=1 to n-1 do for j:=i+1 to n do if s[i]+s[j]<s[j]+s[i] then begin{交换} t:=s[i]; s[i]:=s[j]; s[j]:=t; end; for i:=1 to n do write(s[i]); end.
- 1
Information
- ID
- 708
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By