cf#ECR 9-C - The Smallest String Concatenation-水题
2016-03-02 01:15
363 查看
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;
}
给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;
}
相关文章推荐
- JAVA二学(二)剖析String
- 143 php 接口
- PHP团队编码质量提升之道
- cf#ECR 9-B. Alice, Bob, Two Teams-DP
- c语言数据类型 之 内存对齐与位段
- 程序员必须知道的10大基础实用算法及其讲解
- iOS:手把手教你发布代码到CocoaPods(Trunk方式)
- maven 相关命令记录
- Delphi通过查找字符定位TADOQuery数据的位置
- HDU 4549 M斐波那契数列(矩阵快速幂&费马小定理)
- 5.7 Python API(for Elasticsearch)
- VMware 安装 Ubuntu 12 遇到坑 VMware是什么 不是虚拟机
- JavaScript中创建字典对象(dictionary)实例
- Delphi在DBGridEh改变选中行颜色
- Android中View自定义XML属性详解以及R.attr与R.styleable的区别
- UVA11741 轮廓线动态规划(矩阵加速)
- NDK开发
- JS中遍历普通数组和字典数组的区别
- tomcat日志,根据关键字定位到行
- XmlHttpRequest