UVA10905 Children's Game
题意:给定n个正整数,把它们连接成一个最大的整数.比如,123,124,556,90有24种连接方法,最大的结果为9 056 124 123。
贪心。一开始就想用string水过。注意不能直接用string的一般默认比较方式(字典序),如90和9,应该比较x+y与y+x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | //Serene #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> using namespace std; const int maxn=50+5; int n; string s[maxn]; int aa; char cc; int read() { aa=0;cc= getchar (); while (cc< '0' ||cc> '9' ) cc= getchar (); while (cc>= '0' &&cc<= '9' ) aa=aa*10+cc- '0' ,cc= getchar (); return aa; } bool cmp( const string x, const string y) { return x+y>y+x; } int main() { n=read(); while (n){ for ( int i=1;i<=n;++i) cin>>s[i]; sort(s+1,s+n+1,cmp); for ( int i=1;i<=n;++i) cout<<s[i]; printf ( "\n" ); n=read(); } return 0; } |
弱者就是会被欺负呀
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 历时 8 年,我冲上开源榜前 8 了!
· 物流快递公司核心技术能力-海量大数据处理技术
· 四大AI编程工具组合测评
· 关于能否用DeepSeek做危险的事情,DeepSeek本身给出了答案
· 如何在 Github 上获得 1000 star?