cjweffort

博客园 首页 联系 订阅 管理

new criterion of sorting.

// 1038. Recover the Smallest Number.cpp: 主项目文件。

#include "stdafx.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=10003;
const int Dmax=9;
typedef struct Node{
	char str[Dmax];
}Node;
Node node[N];
int num[N];

bool cmp(Node m1,Node m2){
	char *str1=new char[2*Dmax+1];
	char *str2=new char[2*Dmax+1];
	strcpy(str1,m1.str);
	strcat(str1,m2.str);
	strcpy(str2,m2.str);
	strcat(str2,m1.str);
	return strcmp(str1,str2)<0;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%s",node[i].str);
	sort(node,node+n,cmp);
	bool tag=false;
	for(int i=0;i<n;i++){
		int notZero=0;
		if(!tag){
			while(node[i].str[notZero]!='\0'){
				if(node[i].str[notZero]!='0'){
					tag=true;
					break;
				}
				notZero++;
			}
		}
		printf("%s",node[i].str+notZero);
	}
	if(!tag)
		printf("0");
	printf("\n");
	return 0;
}


posted on 2013-03-13 16:14  cjweffort  阅读(142)  评论(0编辑  收藏  举报