P【1012】拼数

it2026-02-25  13

十分蒟蒻。。。(还是看别人的博才过的。。。)

 

题解

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;string c[21],b[21];int n;bool cmp(string a,string b)//cmp的核心!!!!!(因为这个一直75分。。。

(不要想着从小到大牌再倒着输出,这不行dei)){return a+b>b+a;}int main(){cin>>n;   for(int i=1;i<=n;i++)   {cin>>c[i];b[i]=c[i];    } sort(c+1,c+n+1,cmp); for(int i=1;i<=n;i++)   {cout<<c[i];   }}

p.s cmp用法:

int cmp(  const void*a,const void*b)

{return *(int*)a>*(int*)b}//这是一般的写法

此题因为要比较类似 321与32这类恶心的数,所以要比较a+b与b+a(因为是字符串,所以可以直接加)

转载于:https://www.cnblogs.com/lcez56jsy/p/10428053.html

相关资源:数据结构—成绩单生成器
最新回复(0)