cjweffort

博客园 首页 联系 订阅 管理

http://ac.jobdu.com/problem.php?cid=1040&pid=63

题目描述:

对N个长度最长可达到1000的数进行排序。

输入:

输入第一行为一个整数N,(1<=N<=100)。
接下来的N行每行有一个数,数的长度范围为1<=len<=1000。
每个数都是一个正数,并且保证不包含前缀零。

输出:

可能有多组测试数据,对于每组数据,将给出的N个数从小到大进行排序,输出排序后的结果,每个数占一行。

样例输入:
3
11111111111111111111111111111
2222222222222222222222222222222222
33333333
样例输出:
33333333
11111111111111111111111111111
2222222222222222222222222222222222

// 题目64:大整数排序.cpp: 主项目文件。

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

const int N=101;
typedef struct Node
{
	char str[1003];
	int len;
}Node;
Node node[N];

bool cmp(Node m1,Node m2)
{
	if(m1.len!=m2.len)
		return m1.len<m2.len;
	else
		return strcmp(m1.str,m2.str)<0;
}

int main()
{
    int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%s",node[i].str);
			node[i].len=strlen(node[i].str);
		}
		sort(node,node+n,cmp);
		for(int i=0;i<n;i++)
			printf("%s\n",node[i].str);
	}
    return 0;
}


posted on 2013-03-10 00:24  cjweffort  阅读(170)  评论(0编辑  收藏  举报