求助

P1307 [NOIP2011 普及组] 数字反转

kevin3 @ 2022-08-26 12:20:32

#1TLE

#include<bits/stdc++.h>
using namespace std;
long long s[11]={},n,k=0,a=1;
int main()
{
   memset(s,0,sizeof(n));
   cin>>n;
   for(int i=1;i<=10;i++) s[i]=n/a%10,a*=10;
   a=1000000000;
   for(int i=1;i<=10;i++) k+=s[i]*a,a/=10;
   while(k%10==0) k/=10;
   cout<<k;
   return 0;
}

by _Hu_Tao @ 2022-08-26 12:36:45

@kevin3 ?


by _Hu_Tao @ 2022-08-26 12:37:01

@kevin3 AC代码

#include<iostream>
using namespace std;
int main()
{
    int x,neww;
    cin>>x;
    while(x!=0)
    {
        neww=neww*10+x%10;
        x/=10;
    }
    cout<<neww;
}

by _Hu_Tao @ 2022-08-26 12:37:27

@kevin3 不觉得麻烦?


by _Hu_Tao @ 2022-08-26 12:37:56

@kevin3 求关注QAQ


by aoxiang886 @ 2022-08-26 12:40:47

@kevin3 这样

while(n)

{

ans=ans*10+n%10;

n=n/10;

}


by kevin3 @ 2022-08-26 12:42:48

关了


|