Section 1.2.4 Palindromic Squares 大水

http://www.wzoi.org/usaco/12%5C501.asp

patpat 学习了一个新的stl函数

eg.

  string poi = "poi";

  reverse(poi.begin(), poi.end());

就把poi变成了"iop"

#include <bits/stdc++.h>
using namespace std;
int base;

string trans(int temp){
    int j, ch;
    string ans = "";
    while(temp){
        ch = temp % base;
        if(ch < 10) ans += ch + ‘0‘;
        else ans+= ch - 10 +‘A‘;
        temp /= base;
    }
    return ans;
}
int main()
{

    #ifndef poi
        freopen("palsquare.in","r",stdin);
        freopen("palsquare.out","w",stdout);
    #endif
    string str;
    scanf("%d", &base);
    int i, temp, j, ch, len;
    for(i = 1; i <= 300; i++){
        str = trans(i * i);
        len = str.length();
        for(j = 0; j <= len / 2; j++){
            if(str[j] != str[len - j - 1])  break;
        }
        if(j <= len / 2)    continue;
        string tp = trans(i);reverse(tp.begin(), tp.end());
        cout<<tp<<" "<<str<<endl;

    }
    return 0;
}

时间: 2024-10-13 05:03:20

Section 1.2.4 Palindromic Squares 大水的相关文章

洛谷P1206 [USACO1.2]回文平方数 Palindromic Squares

P1206 [USACO1.2]回文平方数 Palindromic Squares 271通过 501提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且它的平方用B进制表示时是回文数的数.用’A’,’B’……表示10,11等等 输入输出格式 输入格式: 共

USACO 1.2 Palindromic Squares

Palindromic SquaresRob Kolstad Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that

洛谷 P1206 [USACO1.2]回文平方数 Palindromic Squares

题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且它的平方用B进制表示时是回文数的数.用'A','B'--表示10,11等等 输入输出格式 输入格式: 共一行,一个单独的整数B(B用十进制表示). 输出格式: 每行两个B进制的符合要求的数字,第二个数是第一个数的平方,且第二个数是回文数. 输入输出样例 输入样例#1: 10 输出样例#1: 1 1 2 4 3

1.2.4 Palindromic Squares

Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that the square of N is palindromic

[Swust OJ 797]--Palindromic Squares(回文数水题)

题目链接:http://acm.swust.edu.cn/problem/797/ Time limit(ms): 1000 Memory limit(kb): 10000 Description Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 1

Palindromic Squares

链接 分析:求出b进制以后在判是否为回文 1 /* 2 ID:wanghan 3 PROB:palsquare 4 LANG:C++ 5 */ 6 #include "iostream" 7 #include "cstdio" 8 #include "cstring" 9 #include "string" 10 using namespace std; 11 int b; 12 bool judge(string s,int

【USACO 1.2】Palindromic Squares

进制转换,然后判断是否是回文 /******************************************* TASK: palsquare LANG: C++ Created Time: 2016年09月07日 星期三 21时18分46秒 *********************************/ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&

USACO Section1.2 Palindromic Squares 解题报告

palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] 把1~300中,其平方在B进制下是回文数的数进行输出.每个数x输出一行,输出B进制下的x和x²,用空格隔开. 注意,10~

usaco Palindromic Squares

我会告诉你进制转换我都忘了,翻出了数字逻辑课本才想起来的. /* ID: modengd1 PROG: palsquare LANG: 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'