UVA 10905 Children's Game (贪心)
2015-09-15 13:01
344 查看
贪心,假如任意给出一个序列,如果两两交换了以后会变大,那么就交换,直到不能交换为止。
#include<bits/stdc++.h> using namespace std; const int maxn = 51; string s[maxn]; int rk[maxn]; bool cmp(int x,int y) { int i = 0, j = 0, n1 = s[x].size(), n2 = s[y].size(); string *s1 = &s[x], *s2 = &s[y]; int ct = n1+n2; while(ct--){ if(i == n1) i = 0,s1 = &s[y]; if(j == n2) j = 0,s2 = &s[x]; if(s1->at(i) != s2->at(j)) return s1->at(i) < s2->at(j); i++;j++; } return false; } int main() { //freopen("in.txt","r",stdin); ios_base::sync_with_stdio(false); int n; while(cin>>n&&n){ for(int i = 0; i < n; i++) cin>>s[i], rk[i] = i; sort(rk,rk+n,cmp); for(int i = n-1; i>=0; i--) printf("%s",s[rk[i]].c_str()); puts(""); } return 0; }
相关文章推荐
- 留言板 Message Board
- 每日python(7)
- bzoj1607
- spring IOC和DI
- 利用ASP输出excel文件实例讲解
- 抽象类和接口的区别
- 【C/C++学院】0804-C语言和设计模式(继承、封装、多态)
- Longest Consecutive Sequence
- 3D MAX制作游戏高端人物模型
- hdu 5442 Favorite Donut(最大表示法+kmp)
- MiniGUI文档参考手册 基于v1.6.10文本
- PHP 删除非法UTF-8字符
- Intel项目所用jquery小知识点总结
- 查看nginx的版本
- “TI门外汉”网路知识笔记六 VTP的原理及配置
- IM菜鸟学习之Socket聊天-简单服务器的搭建
- apache虚拟目录配置
- 第56讲:Scala中Self Types实战详解
- 自我介绍 Self Introduction
- Linux输入法问题