USACO Section 1.2: Palindromic Squares
2014-03-16 13:34
513 查看
/* ID: leetcod3 PROG: palsquare LANG: C++ */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> #include <list> #include <cstdio> #include <cstdlib> #include <limits> #include <stack> using namespace std; ofstream fout ("palsquare.out"); ifstream fin ("palsquare.in"); string tobase(int x, int base) { string ans = ""; while (x) { int tmp = x % base; if (tmp >= 10) ans.insert(0, 1, 'A'+tmp-10); else ans.insert(0, 1, '0'+tmp); x /= base; } return ans; } bool palin(string s) { for (int i = 0; i < s.size() / 2; i++) { if (s[i] != s[s.size()-1-i]) return false; } return true; } int main() { int base; fin >> base; for (int i = 1; i <= 300; i++) { if (palin(tobase(i*i, base))) fout << tobase(i, base) << " " << tobase(i*i, base) << endl; } return 0; }
相关文章推荐
- USACO-Section1.2 palsquare[字符处理]
- USACO Section 1.2 Palindromic Squares 解题报告
- USACO Section1.2
- USACO - Chapter1 Section 1.2 - Dual Palindromes
- USACO-Section1.2 Milking Cows [线段树]
- USACO-Section1.2 Dual Palindromes【暴力枚举】【查找】
- USACO-Section1.2 Dual Palindromes
- [USACO 1.2] Summary of Section 1.2
- USACO: Section 1.2 -- PROB Dual Palindromes
- USACO-Section1.2 transform[枚举]
- USACO Section 1.2 Milking Cows
- USACO Section 1.2 Dual Palindromes 解题报告
- USACO Section 1.2 Milking Cows
- USACO Chapter1-Getting started Section 1.2
- USACO-Section 1.2 Milking Cow[枚举]
- USACO Section1.2 Transformations
- USACO section1.2 Palindromic Squares
- [USACO Training] Section 1.2
- usaco section1.2 Transformations
- USACO Section1.2 Palindromic Squares