cf#ECR 9-C - The Smallest String Concatenation-水题

http://codeforces.com/contest/632/problem/C


给n个字符串,要求拼接起来得到的串字典序最小


一开始在想怎么搞。。后来发现这个规模无脑暴力一发即可

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001; 
int min(int a,int b)
{
	return a<b?a:b;
}
 struct node
 {
	char s[55];
	bool operator< (const node b)
	{
		string s1,s2;
		s1=s;
		s1+=b.s;
		s2=b.s;
	 	s2+=s; 
		if (s1<s2)
			return true;
		else
			return false;
		
	}
 };
 node tm[5*10000+50];
 
int main()
{
	int n;
	cin>>n;
	int i;
	for (i=1;i<=n;i++)
	{
		scanf("%s",tm[i].s);
	}
sort(tm+1,tm+1+n);
	for (i=1;i<=n;i++)
	{
		printf("%s",tm[i].s);
	}
	printf("\n");


	return 0;
	
}


你可能感兴趣的:(cf#ECR 9-C - The Smallest String Concatenation-水题)