UVA 10905 - Children's Game
来源:互联网 发布:商品条形码制作软件 编辑:程序博客网 时间:2024/06/02 17:45
/*
地址 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1846
题意,给n个数字,将它们重新排序得到一个最大的数字,好像给出444 555 666 拼为 666555444 最大
水题一道,通过比较 A+B > B+A 是否成立,成立的话A在前面,
都以这种规则来排,排完后就是我们需要的最优序列
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string a[55];
int n;
while(cin>>n,n)
{
string s;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++)
for(int j=0;j<n-i;j++){
if(a[j]+a[j+1]<a[j+1]+a[j]){
string temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
for(int i=0;i<n;i++){
cout<<a[i];
}
cout<<endl;
}
return 0;
}
地址 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1846
题意,给n个数字,将它们重新排序得到一个最大的数字,好像给出444 555 666 拼为 666555444 最大
水题一道,通过比较 A+B > B+A 是否成立,成立的话A在前面,
都以这种规则来排,排完后就是我们需要的最优序列
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string a[55];
int n;
while(cin>>n,n)
{
string s;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++)
for(int j=0;j<n-i;j++){
if(a[j]+a[j+1]<a[j+1]+a[j]){
string temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
for(int i=0;i<n;i++){
cout<<a[i];
}
cout<<endl;
}
return 0;
}
0 0
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- uva 10905 - Children's Game
- UVA 10905 Children's Game
- UVa 10905 - Children's Game
- Uva-10905-Children’s Game
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905-Children’s Game
- UVa 10905: Children's Game
- UVA 10905 - Children's Game
- UVA 10905 Children's Game
- UVA 10905 - Children’s Game
- uva 10905 Children's Game
- uva 10905 Children's Game
- 有关case语句
- web.py处理url
- LinuxC -- MySQL
- PHP魔术函数、魔术常量、预定义常量
- 【HDFS】hdfs的fsck是咋回事
- UVA 10905 - Children's Game
- jsp页面实现excl下载,java使用jxl.jar实现excl下载
- Android有线网调试
- 挨踢项目求生法则(7)——实施篇
- BI 入门经典
- win 7下myEcplice 9.0 破解(图文)
- 将Qt imports目录路径作为参数传递
- 奋斗于软件测试(by leo)
- Network Attack