美文网首页
UVA 10018 Reverse and Add

UVA 10018 Reverse and Add

作者: iamkai | 来源:发表于2016-11-18 17:48 被阅读0次

Problem

https://uva.onlinejudge.org/external/100/10018.pdf

Solution

主要是reverse函數, 完成了就差不多了
注意!! : 此題的數字範圍需要用到unsigned
Note: 我把輸入的地方跟解題邏輯拆開

#include<iostream>
using namespace std;

unsigned int reverse(unsigned int num)
{
    unsigned int rev = 0;
    while(num > 0)
    {
        rev = rev * 10 + num % 10;
        num = num / 10;
    }
    return rev;
}

void solve(unsigned int num)
{
    unsigned int count,rev;

    count = 1;
    rev = reverse(num);
    while(1)
    {
        num = rev + num;
        rev = reverse(num);
        if(rev == num)
            break;
        count++;
    }
   
    cout << count << " " << rev << endl;
}


int main()
{
    int testcase;
    unsigned int num;
    
    cin >> testcase;
    while(testcase)
    {
        cin >> num;
        solve(num);
        
        testcase--;
    }
    return 0;
}

Reference

  1. 翼世界夢想領域

相关文章

  • UVA 10018 Reverse and Add

    Problem https://uva.onlinejudge.org/external/100/10018.pd...

  • 2018-10-22

    reverse list find mid remove all nodes in a head add two ...

  • Linked List

    Reverse a Single Linked List Linked List Cycle Add Two Nu...

  • uva10954 Add All

    题目: Yup!! The problem name reflects your task; just add a...

  • 银生宝代付和网关渠道

    1、Channels.java 增加银生宝支付通道UNSPAY(10018,"10018","银生宝"); 2、c...

  • Uva11040 Add bricks in the wall

    题目: This in not “another brick in the wall”, it’s just a ...

  • 感恩奇迹10018

    1.感恩早上起来,我睁开眼睛,看到自己身处的这个世界。 2.感恩马桶,让我排便和小便。 3.感恩烧水壶,给我烧开水...

  • 素数练习题

    UVA 10375 UVA 10791 UVA10375 Choose and divide 题解 先素数打表,然...

  • 有趣的数学题

    UVA12716 UVA11582 UVA12716 GCD XOR 题解 参考这题用到2个结论a ^ b = c...

  • 字典树

    UVA 11488题目链接https://uva.onlinejudge.org/index.php?option...

网友评论

      本文标题:UVA 10018 Reverse and Add

      本文链接:https://www.haomeiwen.com/subject/knkspttx.html