没有头绪,我写的代码怎么跟粑粑一样

P1307 [NOIP2011 普及组] 数字反转

Hayward @ 2022-12-04 20:01:31

#include<iostream>
using namespace std;
int main()
{
    long long n = 0;
    cin >> n;
    if (n >= 10 && n < 100)
    {
        int shi = n / 10;
        int ge = n % 10 * 10;
        cout << ge + shi;
    }
    if (n >= 100 && n < 1000)
    {
        long long bai = n / 100;
        int shi = n % 100 / 10 * 10;
        int ge = n % 10 * 100;
        int sum = bai + shi + ge;
        cout << sum;
    }
    if (n >= 1000 && n < 10000)
    {
        int qian = n / 1000;
        int bai = n % 1000 / 100;
        int shi = n % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 1000 + shi * 100 + bai * 10 + qian;
        cout << sum;
    }
    if (n >= 10000 && n < 100000)
    {
        int wan = n / 10000;
        int qian = n / 1000 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 10000 + shi * 1000 + bai * 100 + qian * 10 + wan;
        cout << sum;
    }
    if (n >= 100000 && n < 1000000)
    {
        int shiwan = n / 10000 / 10;
        int wan = n / 10000 % 10;
        int qian = n / 1000 % 100 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 100000 + shi * 10000 + bai * 1000 + qian * 100 + wan * 10 + shiwan;
        cout << sum;
    }
    if (n >= 1000000 && n < 10000000)
    {
        int baiwan = n / 100000 / 10;
        int shiwan = n % 1000000 / 100000;
        int wan = n / 10000 % 10;
        int qian = n / 1000 % 100 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 1000000 + shi * 100000 + bai * 10000 + qian * 1000 + wan * 100 + shiwan*10+baiwan;
        cout << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan;
    }
    if (n >= 10000000 && n < 100000000)
    {
        int qianwan = n / 1000000/10;
        int baiwan = n % 10000000 / 1000000;
        int shiwan = n % 1000000 / 100000;
        int wan = n / 10000 % 10;
        int qian = n / 1000 % 100 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 10000000 + shi * 1000000 + bai * 100000 + qian * 10000 + wan * 1000 + shiwan * 100 + baiwan*10+qianwan;
        cout << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan<<endl<<qianwan;
    }
    if (n >= 100000000 && n < 1000000000)
    {
        long long yi = n / 100000000;
        long long qianwan = n / 1000000 / 10%10;
        long long baiwan = n % 10000000 / 1000000;
        long long shiwan = n % 1000000 / 100000;
        long long wan = n / 10000 % 10;
        long long qian = n / 1000 % 100 % 10;
        long long  bai = n % 1000 / 100;
        long long shi = n % 10000 % 1000 % 100 / 10;
        long long  ge = n % 1000 % 100 % 10;
        long long  sum = ge * 100000000 + shi * 10000000 + bai * 1000000 + qian * 100000 + wan * 10000 + shiwan * 1000 + baiwan * 100 + qianwan*10+yi;
        cout << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan<<endl<<qianwan<<endl<<yi;
    }
    if (n >= 1000000000 && n < 10000000000)
    {
        long long shiyi = n / 1000000000;
        long long yi = n / 100000000 %10;
        long long qianwan = n / 1000000 / 10 % 10;
        long long baiwan = n % 10000000 / 1000000;
        long long shiwan = n % 1000000 / 100000;
        long long wan = n / 10000 % 10;
        long long qian = n / 1000 % 100 % 10;
        long long  bai = n % 1000 / 100;
        long long shi = n % 10000 % 1000 % 100 / 10;
        long long  ge = n % 1000 % 100 % 10;
        long long  sum = ge * 1000000000 + shi * 100000000 + bai * 10000000 + qian * 1000000 + wan * 100000 + shiwan * 10000 + baiwan * 1000 + qianwan * 100 + yi*10+shiyi;
        cout << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan<<endl<<qianwan<<endl<<yi<<endl<<shiyi;
    }
    if (n >= -10 && n < -100)
    {
        n = n * -1;
        int shi = n / 10;
        int ge = n % 10 * 10;
        int sum = ge + shi;
        cout << "-" << sum;
    }
    if (n >= -100 && n < -1000)
    {
        n = n * -1;
        long long bai = n / 100;
        int shi = n % 100 / 10 * 10;
        int ge = n % 10 * 100;
        int sum = bai + shi + ge;
        cout <<"-"<< sum;
    }
    if (n >= -1000 && n < -10000)
    {
        n = n * -1;
        int qian = n / 1000;
        int bai = n % 1000 / 100;
        int shi = n % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 1000 + shi * 100 + bai * 10 + qian;
        cout <<"-"<< sum;
    }
    if (n >= -10000 && n < -100000)
    {
        n = n * -1;
        int wan = n / 10000;
        int qian = n / 1000 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 10000 + shi * 1000 + bai * 100 + qian * 10 + wan;
        cout << "-" << sum;
    }
    if (n >= -100000 && n < -1000000)
    {
        n = n * -1;
        int shiwan = n / 10000 / 10;
        int wan = n / 10000 % 10;
        int qian = n / 1000 % 100 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 100000 + shi * 10000 + bai * 1000 + qian * 100 + wan * 10 + shiwan;
        cout << "-" << sum;
    }
    if (n >= -1000000 && n < -10000000)
    {
        n = n * -1;
        int baiwan = n / 100000 / 10;
        int shiwan = n % 1000000 / 100000;
        int wan = n / 10000 % 10;
        int qian = n / 1000 % 100 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 1000000 + shi * 100000 + bai * 10000 + qian * 1000 + wan * 100 + shiwan * 10 + baiwan;
        cout <<"-"<< sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan;
    }
    if (n >= -10000000 && n < -100000000)
    {
        n = n * -1;
        int qianwan = n / 1000000 / 10;
        int baiwan = n % 10000000 / 1000000;
        int shiwan = n % 1000000 / 100000;
        int wan = n / 10000 % 10;
        int qian = n / 1000 % 100 % 10;
        int bai = n % 1000 / 100;
        int shi = n % 10000 % 1000 % 100 / 10;
        int ge = n % 1000 % 100 % 10;
        int sum = ge * 10000000 + shi * 1000000 + bai * 100000 + qian * 10000 + wan * 1000 + shiwan * 100 + baiwan * 10 + qianwan;
        cout << "-" << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan<<endl<<qianwan;
    }
    if (n >= -100000000 && n < -1000000000)
    {
        n = n * -1;
        long long yi = n / 100000000;
        long long qianwan = n / 1000000 / 10 % 10;
        long long baiwan = n % 10000000 / 1000000;
        long long shiwan = n % 1000000 / 100000;
        long long wan = n / 10000 % 10;
        long long qian = n / 1000 % 100 % 10;
        long long  bai = n % 1000 / 100;
        long long shi = n % 10000 % 1000 % 100 / 10;
        long long  ge = n % 1000 % 100 % 10;
        long long  sum = ge * 100000000 + shi * 10000000 + bai * 1000000 + qian * 100000 + wan * 10000 + shiwan * 1000 + baiwan * 100 + qianwan * 10 + yi;
        cout <<"-" << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan<<endl<<qianwan<<endl<<yi;
    }
    if (n >= -1000000000 && n < -10000000000)
    {
        n = n * -1;
        long long shiyi = n / 1000000000;
        long long yi = n / 100000000 % 10;
        long long qianwan = n / 1000000 / 10 % 10;
        long long baiwan = n % 10000000 / 1000000;
        long long shiwan = n % 1000000 / 100000;
        long long wan = n / 10000 % 10;
        long long qian = n / 1000 % 100 % 10;
        long long  bai = n % 1000 / 100;
        long long shi = n % 10000 % 1000 % 100 / 10;
        long long  ge = n % 1000 % 100 % 10;
        long long  sum = ge * 1000000000 + shi * 100000000 + bai * 10000000 + qian * 1000000 + wan * 100000 + shiwan * 10000 + baiwan * 1000 + qianwan * 100 + yi * 10 + shiyi;
        cout << "-" << sum;
        //cout << ge << endl << shi << endl << bai << endl << qian << endl << wan << endl << shiwan << endl << baiwan<<endl<<qianwan<<endl<<yi<<endl<<shiyi;
    }
}

by Katz @ 2022-12-04 20:31:22

@colin1112 不会教可以不教


by _colin1112_ @ 2022-12-04 20:32:13

@VT_SODC3DC3BSLF 啊这......要说我给他提思路,可上一个人已经给他提了,他还是不懂,所以我只好给他上代码了


by VitrelosTia @ 2022-12-04 20:33:38

@colin1112 他连思路都不懂为什么会懂代码?你给他代码最有可能的就是他直接复制代码然后觉得自己懂了


by Katz @ 2022-12-04 20:33:42

@colin1112 41篇题解不看看你的?


by Katz @ 2022-12-04 20:34:55

@colin1112 有没有一种可能,老师存在的意义不是告诉你1+1=2而是告诉你为什么1+1=2


上一页 |