题目意思很简单啦,就是找回文
使用string可以高速A过
Source code:
/* ID: wushuai2 PROG: palsquare LANG: C++ */ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <stack> #include <map> #include <queue> #include <vector> #include <algorithm> #define ll long long #define Max(a,b) (((a) > (b)) ? (a) : (b)) #define Min(a,b) (((a) < (b)) ? (a) : (b)) #define Abs(x) (((x) > 0) ? (x) : (-(x))) using namespace std; const int INF = 0x3f3f3f3f; string solve(int base, int n){ string ss; while(n){ if(n % base > 9){ ss.push_back(n % base - 10 + ‘A‘); } else{ ss.push_back(n % base + ‘0‘); } n /= base; } reverse(ss.begin(), ss.end()); return ss; } bool judge(string ss){ string pp = ss; reverse(ss.begin(), ss.end()); if(ss.compare(pp) == 0){ return true; } return false; } int main() { ofstream fout ("palsquare.out"); ifstream fin ("palsquare.in"); int base; fin >> base; for(int i = 1; i <= 300; ++i){ if(judge(solve(base, i * i))){ fout << solve(base, i) << ‘ ‘ << solve(base, i * i) << endl; } } return 0; }
时间: 2024-11-11 21:02:01