Usaco Section1.2 palindromic squares Problem Solving Report

Source: Internet
Author: User

Palsquare Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
In the 1~300, the square in the B-system is the number of palindrome number to output. Each number x outputs a row, and the X and x ² in the output B are separated by a space.
Note that these numbers, 10~19, are denoted by capital letters ' A ', ' B ', and so on.
"Data Range"
1<=b<=20
"Input Sample"
10
"Output Example"
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
There is no difficulty in making the conversion.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
The binary conversion made a small mistake, and the output was cout from the beginning.

--------------------------------------------------------------------------------------------------------------- ---------------------------------

Code

1 /*2 id:icedrea13 Prob:palsquare4 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten  One intB; A Charto[ -]={'0','1','2','3','4','5','6','7','8','9', -                 'A','B','C','D','E','F','G','H','I','J'  }; -  the stringChangeintx) - { -     stringnum; -      while(x) {num=to[x%b]+num; x/=B;} +     returnnum; - } +  A BOOLIspal (intx) at { -     stringNum=change (x*x); -      for(intI=0; I!=num.size (); + +i) -         if(Num[i]!=num[num.size ()-1-I.])return false; -     return true; - } in  - intMain () to { +Ifstreaminch("palsquare.in"); -Ofstream out("Palsquare.out"); the  *     inch>>B; $      for(intI=1; i<= -;++i)Panax Notoginseng     { -         if(!ispal (i))Continue; the          out<<change (i) <<" "<<change (i*i) <<Endl; +     } A  the     inch. Close (); +      out. Close (); -     return 0; $}

Usaco Section1.2 palindromic squares Problem Solving Report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.