cf(次方)函数好像出问题了,就只过了四个测试点,但换成math库的pow()和把cf中的cf变量换成long long型就能AC,但题目数据不是刚好不会爆int吗,没懂为啥用Int会炸,有神犇解答下吗TvT
#include <iostream>
#include <cstdio>
#include <cstring>
#include<algorithm>
#include<math.h>
using namespace std;
#define MAXN 25
int a[MAXN];
int get_ws(int x)
{
int ws=0;
while(x)
{
x/=10;
ws++;
}
return ws;
}
int cf(int x)
{
int cf=1;
for(int i=0;i<x;i++)
{
cf*=10;
}
return cf;
}
bool com(int x,int y)
{
long long tmpx=x*cf(get_ws(y))+y;//32*1000+321=32321
long long tmpy=y*cf(get_ws(x))+x;//321*100+32=32132
return tmpx >tmpy ;//x>y
}
int main()
{
int n;
scanf("%d",&n);
memset(a,0,MAXN);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a, a+n, com);
for(int k=0;k<n;k++)
{
printf("%d",a[k]);
}
return 0;
}