Usaco Section1.2 Dual palindromes Problem Solving report

Source: Internet
Author: User
Tags binary to decimal

Dualpal Problem Solving report--icedream61 Blog Park (reproduced please specify the source)
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Topic
Give N and S to find the first n double palindrome numbers greater than S.
Double palindrome number definition: two (or more) binaries in binary to decimal are palindrome numbers.
"Data Range"
1<=n<=15
0<s<10000
Integer variables greater than 4 bytes are not required
"Input Sample"
3 25
"Output Example"
26
27
28
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Analysis
No difficulty.
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Summary
It's a pity that it's not AC again. (in Main, the word "--n" forgot to write.) )

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

Code

1 /*2 id:icedrea13 Prob:dualpal4 lang:c++5 */6 7#include <iostream>8#include <fstream>9 using namespacestd;Ten  One intn,s; A  - Charto (intx) {returnX-1+'1'; } - stringChangeintXintB) the { -     stringnum; -      while(x) {num=to (x%b) +num; x/=B;} -     returnnum; + } - BOOLIspal (stringnum) + { A      for(intI=0; I!=num.size (); + +i) at         if(Num[i]!=num[num.size ()-1-I.])return false; -     return true; - } -  - intMain () - { inIfstreaminch("dualpal.in"); -Ofstream out("Dualpal.out"); to  +     intCNT; -     inch>>N>>S; the      while(N) *     { $cout<<"n="<<N<<Endl;Panax Notoginseng++s; Cnt=0; -          for(intb=2; b<=Ten; ++b) cnt+=Ispal (Change (s,b)); the         if(cnt>=2) { out<<S<<endl; --N;} +     } A  the     inch. Close (); +      out. Close (); -     return 0; $}

Usaco Section1.2 Dual palindromes 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.