CodeForces-632C-The Smallest String Concatenation(水题报告,学习sort用法)

题目链接:http://codeforces.com/problemset/problem/632/C

题意也简单,输入n个字符串,从长到短依次输出,用string+sort就可以解决

对于bool来说,一个整数,非零即为真。也就是整数的0对应于False; 其它的值(如-1和1)对应于True;

string字符串比较长度的方法:https://blog.csdn.net/fanyun_01/article/details/79122843

#include<iostream>
#include<cstdio>
#include<cstring> 
#include<algorithm>
#define MAX 50005
using namespace std;
bool cmp(string a,string b)
{
	if(a.length()>b.length()) return 1;
	else return 0;
	
}
int main()
{
	string s[MAX];
	int i,j,n;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=1;i<=n;i++)
		cin>>s[i];
		sort(s+1,s+n+1,cmp);
		for(i=1;i<=n;i++)
		cout<<s[i];
		printf("\n");
		
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/zvenWang/article/details/81808271