70pts求助

P1307 [NOIP2011 普及组] 数字反转

DoubleCats @ 2024-08-05 21:42:06

代码:

#include<bits/stdc++.h>
#define ll long long 
#define sort stable_sort
using namespace std;
//writen by DoubleCats
ll n;
string a;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin>>a;
    if(a=="-0"){
        cout<<0;
        return 0;
    }
    if(a[0]!='-'){
        reverse( a.begin() , a.end() );
    }
    else {
        reverse( a.begin()+1 , a.end() );
    }
    int len=a.size();
    for(int i=0;i<=len-1;i++){
        if(a[i]=='0'&&i!=len-1) continue;
        if(a[i]=='0'&&i==len-1){
            cout<<a[i];
            continue;
        } 
        cout<<a[i];
    }

    return 0;
}

记录 #7 #9 #10 WA


by Jokersheng @ 2024-08-05 21:44:31

#include <bits/stdc++.h>
using namespace std;

int n,m;

int main(){
    cin>>n;
    while(n){
        m=m*10+n%10;
        n/=10;
    }
    cout<<m;
    return 0;
}

不就是个拆位吗?没必要打高精


by HACKER_ONE @ 2024-08-06 11:09:12

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,x,a[101]={},s=1;
    bool f=0;
    scanf("%d",&n);
    if(n==0) printf("0");
    x=n;
    int k=1;
    if(x<0) x=-x,f=1;
    while(x!=0)
    {
        a[k]=x%10;
        x/=10;
        k++;
    }
    while(a[s]==0)
    {
        s++;
    }
    if(f==1) printf("-");
    for(int i=s;i<k;i++) printf("%d",a[i]);
    return 0;
}

|