Java AC
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.util.Arrays; import java.util.Comparator; public class Main { /* * 2014年5月15日14:26:30 */ public static void main(String[] args) throws Exception { StreamTokenizer st = new StreamTokenizer(new BufferedReader( new InputStreamReader(System.in))); while (st.nextToken() != StreamTokenizer.TT_EOF) { int n = (int) st.nval; Integer array[] = new Integer[n]; for (int i = 0; i < n; i++) { st.nextToken(); array[i] = (int) st.nval; } StrSort strSort = new StrSort(); Arrays.sort(array, strSort); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(array[i]); } System.out.println(sb); } } } class StrSort implements Comparator<Integer> { public int compare(Integer o1, Integer o2) { String numStr1 = o1 + "" + o2; String numStr2 = o2 + "" + o1; return numStr1.compareTo(numStr2); } } /************************************************************** Problem: 1504 User: wangzhenqing Language: Java Result: Accepted Time:1960 ms Memory:149288 kb ****************************************************************/C++ AC
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; const int maxn = 102; int n, i; struct Node{ char num[20]; }nodes[102]; bool cmp(Node node1,Node node2){ char c[20]; strcpy(c,node1.num); strcat(node1.num,node2.num); strcat(node2.num,c); return strcmp(node1.num,node2.num) < 0; } int main(){ int n; while(scanf("%d",&n)!=EOF){ for(i = 0; i < n; i++){ scanf("%s",nodes[i].num); } sort(nodes,nodes+n,cmp); for(i = 0; i < n; i++){ printf("%s",nodes[i].num); } printf("\n"); } return 0; } /************************************************************** Problem: 1504 User: wangzhenqing Language: C++ Result: Accepted Time:80 ms Memory:1028 kb ****************************************************************/