进入USACO要注册才能看题: http://train.usaco.org/usacogate
题目:【翻译版、是别处的网站】http://www.wzoi.org/usaco/12%5C501.asp
SAMPLE INPUT (file palsquare.in)
10
SAMPLE OUTPUT (file palsquare.out)
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696 //结果中2个数都要以所给进制输出
水题……但是由于细节问题没能一次A……无奈
/*
ID: 1006100071
PROG: palsquare
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <set>
//#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <stack>
#include <list>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
using namespace std;
char num[] = {"0123456789ABCDEFGHIJKLMNO"};
inline bool ispalind (char *s, int len) //判断s是否回文
{
int i;
for (i = 0; i < len / 2; i++)
if (s[i] != s[len-1-i])
return false;
return true;
}
void my_itoa (int a, char *s, int b)//把a转成b进制放到s中,n为0时失效,根据题意没有0的情况!
{
int k = 0, i;
char p[30];
while (a)
{
p[k++] = num[a % b];
a /= b;
}
p[k] = 0;
for (i = 0; i < k; i++) //反转字符串
s[i] = p[k-1-i];
s[k] = 0;
//cout << s << endl;
}
int main()
{
/*freopen ("palsquare.in", "r", stdin);
freopen ("palsquare.out", "w", stdout);*/
char s1[30], s[30];
int n, len, b;
while (scanf ("%d", &b) != EOF)
{
for (n = 1; n <= 300; n++)
{
my_itoa (n * n, s, b);
len = strlen(s);
if (ispalind (s, len))
{
my_itoa (n, s1, b);
printf ("%s %s\n", s1, s);
}
}
}
return 0;
}
分享到:
相关推荐
USACO题目Palindromic Squares(回文平方数)及代码解析
USACO全部译题,美国题库USACO全部译题,超经典的题目
USACO 官网第一到 五章 练习题中文语言官方数据 fps格式支持导入所有OJ 1 [1.1] 你的飞碟在这儿 Your Ride Is Here 2 [1.1] 贪婪的送礼者Greedy Gift Givers 3 [1.1] 黑色星期五Friday the Thirteenth 4 [1.1] 坏掉...
美国著名题库USACO的经典试题,配上测试数据和pascal的std标程。祝OIers在信息竞赛的道路上能走得远
其中包含了USACO前些年的月赛试题和部分试题的数据,部分试题的详细题解,英文原题目与翻译后的题目,与题解一一对应
usaco 合集,包括英文原题和中文译题,测试数据以及答案,很全啊!usaco 合集usaco 合集usaco 合集usaco 合集
USACO做题代码
此C++程序是实现了USACO网站上的Magic Squares的问题。
仅提供usaco 2006 mar 数据,2006其它时间网上很多。美国著名题库USACO的经典试题,祝OIers在信息竞赛的道路上能走得远
这个是USACO题库中选出来的一些题,覆盖了多方面的知识点,利于锻炼C++学者的算法,里面还有部分题解
USACO月赛的金组题目,从2000-2009 , 全中文翻译。
数据结构机考所参考的USACO网站所有题目的解题思路,资源比较稀有!
含2001~2017全部比赛赛题测试...2001~2007 数据√ 题面× 标程题解× 2008~2010 数据√ 题面√ 标程题解× 2011~2017 数据√ 题面√ 标程题解√ 其中除2008~2010外其他年份均按照年度、月度、金银铜白金组别整理完全
pku acm上的一系列usaco题目都可以在这里找到测试数据以及源代码,不过题目的名字和pku上有得有点出入,需要自己去比较一下,2002年
usaco历年测试数据
USACO题集及答案
USACO的一些题目代码和月赛十年题典,以及部分题解
USACO题解及中文译题1.1.1-2.4.5 题目为TXT格式文档,代码为C++语言所编写
USACO所有题目的题解 NOCOW整理版