T1U3348 A2-回文数

https://www.luogu.org/problem/show?pid=U3348

考场上钻了牛角尖了,然后0分

#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
LL cnt[101];
int ans[101];
int main()
{
        LL n;
        scanf("%lld",&n);
        LL now=9;
        int len;
        for(len=1;;len++)
        {
                if(n>now) n-=now;
                else break;
                if(len%2==0) now*=10;
        }
        int i=len+1>>1;
        n--;
        LL tmp=1;
        for(int j=1;j<i;j++) tmp*=10;
        for(int j=1;j<i;j++)
        {
                for(int k=(j==1);k<=9;k++)
                {
                        if(j==1 && k==1) ans[j]=1;
                        if(n>=tmp) ans[j]++,n-=tmp;
                        else break;
                }
                tmp/=10;
        }
        for(int j=1;j<i;j++) printf("%d",ans[j]);
        printf("%d",n);
        if(len%2==0) printf("%d",n);
        for(int j=i-1;j;j--) printf("%d",ans[j]);
}        
View Code

相关文章:

  • 2021-11-11
  • 2022-01-10
  • 2021-12-06
  • 2022-02-02
  • 2021-11-27
  • 2021-10-11
  • 2022-02-04
  • 2021-08-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-10-24
  • 2021-12-12
  • 2021-10-05
  • 2021-10-02
相关资源
相似解决方案