这题一开始比较错了。两字符串比较应该是 ab和ba两字符串连接起来比较,谁在前面大就排前面。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; struct Num{
char str[1000];
}num[60]; char tmp1[1000],tmp2[1000]; bool cmp(Num s,Num t){
strcpy(tmp1,s.str);
strcat(tmp1,t.str);
strcpy(tmp2,t.str);
strcat(tmp2,s.str);
int len=strlen(tmp1);
for(int i=0;i<len;i++)
if(tmp1[i]<tmp2[i]) return false;
else if(tmp1[i]>tmp2[i]) return true;
if((int)strlen(s.str)<(int)strlen(t.str)) return true;
return false;
} int main(){
int n;
while(scanf("%d",&n),n){
for(int i=0;i<n;i++)
scanf("%s",num[i].str);
sort(num,num+n,cmp);
for(int i=0;i<n;i++)
printf("%s",num[i].str);
puts("");
}
return 0;
}

  

UVA 10905的更多相关文章

  1. uva 10905 Children's Game (排序)

    题目连接:uva 10905 Children's Game 题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大. 解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面.可 ...

  2. UVA 10905 Children's Game 孩子的游戏 贪心

    题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...

  3. UVa 10905 - Children's Game 排序,题目没有说输入是int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  4. UVa 10905 Children's Game

    注意!这不是单纯的字典序排序,比如90.9,应该是990最大 对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过. 看别人用string还是比较方便的,学习一下 对了,这里的cmp函 ...

  5. 【字符串排序,技巧!】UVa 10905 - Children’s Game

    There are lots of number games for children. These games are pretty easy to play but not so easy to ...

  6. UVA 10905 Children's Game (贪心)

    Children's Game Problem Description There are lots of number games for children. These games are pre ...

  7. Children's Game UVA - 10905

    看90,956这样的串,在比较完之前,就确定大小的,必定选大的放在前.而x=98,y=980;这样的,比较x+y和y+x的大小.如果x+y更小,y就放前. #include <iostream& ...

  8. UVa 10905 孩子们的游戏

    https://vjudge.net/problem/UVA-10905 题意: 给定n个正整数,把它们连接成一个最大的整数. 思路: 实在是没想到直接用string来排序了. #include< ...

  9. UVa 10905 - Children's Game(求多个正整数排列后,所得的新的数字的极值)

    4thIIUCInter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: st ...

  10. UVA 10905 Children's Game (贪心)

    贪心,假如任意给出一个序列,如果两两交换了以后会变大,那么就交换,直到不能交换为止. #include<bits/stdc++.h> using namespace std; ; stri ...

随机推荐

  1. asp.net core 2.0 Json结果的格式

    asp.net core 2.0 默认返回的结果格式是Json, 并使用json.net对结果默认做了camel case的转化(大概可理解为首字母小写). 这一点与老.net web api 不一样 ...

  2. BZOJ 3456 NTT图的计数 容斥

    思路: RT 懒得写了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm&g ...

  3. Oracle(一)

    1.树形表,查询 所有的下边的记录 情景:根据当前记录的ID,要查询其所有子记录,每个子记录再查询当前子记录的所有子记录,如果有的话,一直迭代下去 当前表结构: CREATE TABLE " ...

  4. Linux下安装Wine 运行、卸载 windows程序

    资料 首页 https://www.winehq.org/ 安装 https://www.winehq.org/download/ 教程 https://www.winehq.org/document ...

  5. 12 C#中的方法

    还记得我们的第一个程序吗?忘记了?那你要努力了.我们的第一个程序是就是往dos窗口输出一些字符串.在哪个程序中只有一个方法,Main方法.Main方法是一个特殊的方法,但是它也是一个方法.为什么说Ma ...

  6. 如何让win32 c++窗口不出现在任务栏

    把窗口作为某一个窗口的子窗口,然后设置WS_POPUP就可以了.使用CreateWindow时的第三个参数设置为WS_CHILD|WS_POPUP.

  7. win32绘图基础

     获取设备环境句柄: (1)WM_PAINT消息中: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps ...

  8. jQuery——开关灯

    js对象与jquery对象的相互转化: 1.$(js对象) 2.$(selector).get(索引).$(selector)[索引] <!DOCTYPE html> <html l ...

  9. Zip, Join, GroupJoin

    Zip 合并兩個序列,產生一個新的對象序列,但連接方式是一对一的(即序列1和第一项连接序列2的第一项),所以最终结果会在较短的序列处终止. Zip在這裏不是壓縮的意思,而是拉鏈,意爲連接兩個序列 Pe ...

  10. phpCURL抓取网页内容

    参考代码1:<?php // 创建一个新cURL资源 $ch = curl_init(); // 设置URL和相应的选项 curl_setopt($ch, CURLOPT_URL, " ...