Usaco palindromic Squares

Source: Internet
Author: User

I'll tell you the conversion. I forgot that I had the digital logic textbook in mind.

/*id:modengd1prog:palsquarelang:c++*/#include <iostream> #include <stdio.h> #include <string.h># Include <stack>using namespace Std;char leter[20]={' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J '};//conversion, convert x into a string representation of the number of base binary in the Out array void changethebase (int x,int Base,char out[60]) {stack    <char> S;    int i=0;        while (x>0) {s.push (leter[x%base]);    X/=base; } for (i=0;!        S.empty (); i++) {out[i]=s.top ();    S.pop (); } out[i]=0;}    Detects if a string ending with ' \ ' is not a palindrome string bool Ispalindromic (char input[60]) {int temp[60];    int Len=strlen (input);    for (int i=0;i<len;i++) {temp[len-i-1]=input[i];    } for (int i=0;i<len;i++) {if (Input[i]!=temp[i]) return false; } return true;    int main () {freopen ("palsquare.in", "R", stdin);    Freopen ("Palsquare.out", "w", stdout);    int square[301],base;    scanf ("%d", &base); for (int i=1;i<=300;i++) {CHar out1[60],out2[60];        Changethebase (I,BASE,OUT1);        Changethebase (I*I,BASE,OUT2);        if (Ispalindromic (Out2)) {cout<<out1<< ' <<out2<<endl; }} return 0;}

  

Usaco palindromic Squares

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.