题解

71 条题解

  • 3
    @ 2017-07-22 17:21:08

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    int main()
    {
    int a,b=0;
    scanf("%d",&a);
    while(a!=0)
    {
    b=10*b+a%10;
    a/=10;
    }
    printf("%d",b);
    return 0;
    }

  • 1
    @ 2017-11-25 10:46:50

    对于0xx 可以先把结果存储在新变量中 最后输出该变量 如果需要0的话 就用以0占位的方式 %0xd

    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main()
    {
        int a,b=0;
        scanf("%d",&a);
        while(a!=0)
        {
            b=b*10+a%10;
            a/=10;
        }
        printf("%d",b);
        return 0;
    }
    
  • 1
    @ 2017-10-20 22:42:08

    var
    s,x:string;
    c,i:longint;
    begin
    readln(s);x:='';
    if s[1]='-' then begin
    for i:=length(s) downto 2 do x:=x+s[i];
    val(x,c);writeln('-',c);
    end
    else begin
    for i:=length(s) downto 1 do x:=x+s[i];
    val(x,c);writeln(c);
    end;
    end.

  • 1
    @ 2017-10-04 21:40:17

    char类型读入倒读搞定。
    #include <iostream>
    using namespace std;

    char arr[10];
    int i=0;
    char a;
    bool truefalse=false;

    int main() {
    a=getchar();
    if(a!='-'){
    while(a!='\n'){
    arr[i]=a;
    a=getchar();i++;
    }
    }else{
    truefalse=true;
    a=getchar();
    while(a!='\n'){
    arr[i]=a;
    a=getchar();i++;
    }
    }
    if(truefalse==true){
    cout<<'-';truefalse=false;
    }
    int number=0;
    for(int j=i-1;j>=0;j--){
    if(number==0){
    if(arr[j]!='0'){
    cout<<arr[j];number=1;truefalse=true;
    }
    }else{
    cout<<arr[j];
    }
    }
    if(truefalse==false){
    cout<<0;
    }
    return 0;
    }

  • 1
    @ 2017-09-21 15:27:46

    第一遍想错了N的范围
    把数组开到了1000000000
    但是居然AC了
    仔细一看题发现并不需要
    2333

    #include<cstring>
    using namespace std;
    char c[100];
    int main()
    {
        int num,i,flag=0;
        cin>>c;
        num=strlen(c);
        if(c[0]=='-')
         {
          cout<<"-";
          for(i=num-1;i>0;i--)
          {
            if(!flag)
            {
                if(c[i]=='0')
                continue;
                else
                {
                    flag=1;
                    cout<<c[i];
                }
            }
            else
            cout<<c[i];
          }
         }
         else
         for(i=num-1;i>=0;i--)
          {
            if(!flag)
            {
                if(c[i]=='0')
                continue;
                else
                {
                    flag=1;
                    cout<<c[i];
                }
            }
            else
            cout<<c[i];
          }
        return 0;
    }
    
    
  • 0
    @ 2017-11-25 10:47:26
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main()
    {
        int a,b=0;
        scanf("%d",&a);
        while(a!=0)
        {
            b=b*10+a%10;
            a/=10;
        }
        printf("%d",b);
        return 0;
    }
    
  • 0
    @ 2017-11-04 20:00:46

    直接模拟

    pascal
    cpp
    var
    s:int64;
    f:boolean;
    //标志开头的0是否已完
    begin
    read(s);
    if s=0 then begin write(0);exit;end;
    //特殊情况的处理
    if s<0 then write('-');
    s:=abs(s);
    //处理负数
    while s>0 do
    begin
    if (s mod 10 <>0)or(f) then begin f:=true;write(s mod 10);end;
    s:=s div 10;
    end;
    end.

  • 0
    @ 2017-10-22 09:05:01

    #include<stdio.h>
    int n,s=0;
    int main()
    {
    scanf("%d",&n);
    if(n<0)
    {
    printf("-");
    n=-n;
    }
    while (n!=0)
    {
    s=s*10+n%10;
    n=n/10;
    }
    printf("%d\n",s);
    return 0;

    }

    • @ 2017-10-22 09:05:55

      H2O的一道题

  • 0
    @ 2017-10-01 09:06:50

    500 3
    150 300
    100 200
    470 471


  • 0
    @ 2017-08-22 02:47:52

    so water

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int main()
    {
        char a[10000]={0},w,i=0,n=1,e=0;
        w=getchar();
        while(w!='\n'&&w!=EOF&&w!='\0')
        {
            if(i==0&&w=='-')
                printf("-");
            else
            {
                i++;
                a[i]=w;
            }
            w=getchar();
        }
        n=i;
        for(i=n;i>=1;i--)
        {
            if(e!=0||a[i]!='0')
            {
                e=1;
                printf("%c",a[i]);
            }   
        }
        return 0;
    }
    
  • 0
    @ 2017-07-17 09:43:48

    Accepted

    /usr/bin/ld.bfd: warning: /out/link.res contains output sections; did you forget -T?

    状态 耗时 内存占用

    #1 Accepted 1ms 256.0KiB
    #2 Accepted 1ms 256.0KiB
    #3 Accepted 1ms 256.0KiB
    #4 Accepted 1ms 256.0KiB
    #5 Accepted 1ms 256.0KiB
    #6 Accepted 1ms 256.0KiB
    #7 Accepted 1ms 256.0KiB
    #8 Accepted 1ms 184.0KiB
    #9 Accepted 1ms 256.0KiB
    #10 Accepted 1ms 256.0KiB
    代码

    var
    s,x:string;
    c,i:longint;
    begin
    readln(s);x:='';
    if s[1]='-' then begin
    for i:=length(s) downto 2 do x:=x+s[i];
    val(x,c);writeln('-',c);
    end
    else begin
    for i:=length(s) downto 1 do x:=x+s[i];
    val(x,c);writeln(c);
    end;
    end.

  • 0
    @ 2017-07-07 16:49:02
    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    
    int main(){
        int num = 0;
        bool sign = false;
        cin >> num;
        if (num < 0) sign = true;
        int result = 0;
        while (num != 0){
            int last = num % 10;
            result = result * 10 + last;
            num /= 10;
        }
        //if (sign) result *= -1;
        cout << result << endl;
    }
    
  • 0
    @ 2017-01-12 17:26:41

    #include<stdio.h>

    int main()
    {
    int n,ans=0;
    scanf("%d",&n);
    while(n)
    {
    ans*=10;
    ans+=n%10;
    n/=10;
    }
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2016-12-19 19:24:55

    哈哈 Ac了
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char sh[11];
    scanf("%s",sh);
    int len = strlen(sh);
    int i;
    if(sh[0] == '-')
    {
    printf("-");
    }
    if(sh[0] == '0')
    {
    printf("0");
    return 0;
    }
    int sign = 0;
    for(i=len-1; i >= 0; i--)
    {
    if(sh[i] != '0')
    {
    sign = 1;
    }
    // printf("i = %d sign = %d\n",i,sign);
    if(sh[i] != '-'&&sign == 1)printf("%c",sh[i]);

    }
    return 0;
    }

  • 0
    @ 2016-12-19 17:58:55

    评测结果
    编译成功

    Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
    Copyright (c) 1993-2015 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    Linking foo.exe
    29 lines compiled, 0.0 sec, 26512 bytes code, 1268 bytes data
    测试数据 #0: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 812 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 812 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    Accepted, time = 0 ms, mem = 812 KiB, score = 100
    代码
    var t:char;
    s:string;
    o,i,f:longint;
    fs:boolean;
    begin
    read(s);
    if s[1]='-' then
    begin
    fs:=true;
    delete(s,1,1);
    end;
    o:=length(s)+1;
    f:=length(s) div 2;
    for i:=1 to f do
    begin
    t:=s[i];
    dec(o);
    s[i]:=s[o];
    s[o]:=t;
    end;
    for i:=1 to length(s)+1 do
    begin
    if s[1]<>'0' then break;
    if s[1]='0' then delete(s,1,1);
    end;
    if fs then write('-');
    write(s);

    end.

  • 0
    @ 2016-11-18 15:54:22

    #include<bits/stdc++.h>
    using namespace std;
    char a[1000];
    int main()
    {
    int i,j,k,n,m;
    cin>>a;
    n=strlen(a);
    if(a[0]=='-')
    {
    cout<<a[0];
    for(i=n-1;i>0;i--)
    {
    if(a[i]!='0')
    {
    k=i;
    break;
    }
    }
    for(i=k;i>0;i--)
    cout<<a[i];
    }
    else
    {
    for(i=n-1;i>=0;i--)
    {
    if(a[i]!='0')
    {
    k=i;
    break;
    }
    }
    for(i=k;i>=0;i--)
    cout<<a[i];
    }
    return 0;
    }

  • 0
    @ 2016-11-01 18:45:36

    不明白为什么要用字符处理

    #include<cstdio>
    int n;
    main()
    {
    scanf("%d",&n);
    if(n<0){printf("-");n*=-1;}
    while(n%10==0) n/=10;
    while(n!=0)
    {
    printf("%d",n%10);
    n/=10;
    }
    }

  • 0
    @ 2016-10-05 14:36:11

    Free Pascal Compiler version 3.0.0 [2015/11/16] for i386
    Copyright (c) 1993-2015 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    Linking foo.exe
    20 lines compiled, 0.0 sec, 26592 bytes code, 1268 bytes data
    测试数据 #0: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #4: Accepted, time = 15 ms, mem = 808 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 804 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 812 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 808 KiB, score = 10
    Accepted, time = 15 ms, mem = 812 KiB, score = 100
    代码
    ```pascal
    var a,t:longint;
    inp:char;
    fs:boolean;

    begin
    fs:=false;
    read(inp);
    if inp='-' then begin
    a:=0;t:=1;fs:=true;
    end else begin
    a:=ord(inp)-ord('0');t:=10;
    end;
    while not eoln do begin
    read(inp);
    inc(a,(ord(inp)-ord('0'))*t);
    t:=t*10;
    end;
    if fs then write('-');
    writeln(a);
    end.
    ```

  • 0
    @ 2016-09-24 19:32:43
    #ifndef _DEBUG
    #pragma GCC optimize(2)
    #ifdef Full_Cpp_Compiler
    #include <codecvt>
    #endif
    #include <sstream>
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <memory>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <cmath>
    #include <queue>
    #include <cstring>
    #include <fstream>
    #include <Windows.h>
    #include <iterator>
    #include <set>
    #include <process.h>
    #include <ctime>
    #include <utility>
    #include <cctype>
    #include <bitset>
    #include <stdarg.h>
    #define max(a,b) (a>b?a:b)
    #define min(a,b) (a>b?a:b)
    #endif // _DEBUG
    
    int main() {
        std::ios_base::sync_with_stdio(false);
    
        std::string str;
        int pos;
        std::cin >> str;
        pos = str.size()-1;
        while (str[pos] == '0' || str[pos] == ' ') {
            pos--;
        }
        int end = 0;
        if (str[0] == '-') { std::cout << "-"; end = 1; }
        for (int i = pos; i >= end; i--) {
            std::cout << str[i];
        }
    #ifdef  _DEBUG
        system("pause");
    #endif //  _DEBUG
        return 0;
    }
    
  • 0
    @ 2016-08-24 21:10:26

    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b;
    b=0;
    cin>>a;
    do{
    b=b*10+a%10;
    a=a/10;
    }while(a!=0);
    cout<<b;
    return 0;
    }
    此题真是水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水水!

信息

ID
1756
难度
4
分类
模拟 点击显示
标签
递交数
3799
已通过
1700
通过率
45%
被复制
5
上传者