如果一个正整数n至少在两个不同的进位制b1和b2下都是回文数(2<=b1,b2<=10< span="">),则称n是双基回文数(注意,回文数不能包含前导零)。输入十进制的正整数S<106,输出比S大的最小双基回文数(十进制)
1600000
1632995
http://nnsznoi.openjudge.cn/directlycalculatin/0004/
第一想法尝试用itoa,但是g++不支持。
因此需要自己实现itoa,参考http://stackoverflow.com/questions/228005/alternative-to-itoa-for-converting-integer-to-string-c
string itoa(int a) { string ss=""; //create empty string while(a) { int x=a%10; a/=10; char i='0'; i=i+x; ss=i+ss; //append new character at the front of the string! } return ss; }
但发现运行的很慢,因此需要避免char相加,改进如下:
string myitoa(int a, int base) { string ss; ss.clear(); while(a) { ss += (a%base); a /= base; } return ss; }
AC code:
#define RUN #ifdef RUN /** http://nnsznoi.openjudge.cn/directlycalculatin/0004/ */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <vector> #include <list> #include <cctype> #include <algorithm> #include <utility> #include <math.h> using namespace std; #define LL long long #define MAXN 1000001 char tmp[MAXN]; string myitoa(int a, int base) { string ss; ss.clear(); while(a) { ss += (a%base); a /= base; } return ss; } bool isPalindrome(string s){ int len = s.length(); for(int i=0; i<len/2; i++){ if(s[i] != s[len-1-i]){ return false; } } return true; } void check(LL n){ LL test = n+1; for(;;){ int cnt = 0; for(int i=2; i<=10; i++){ //itoa(test, tmp, i); string s = myitoa(test, i); if(isPalindrome(s)){ //cout << test << "--" << s << "---" << cnt << endl; cnt++; if(cnt >= 2){ cout << test << endl; return; } } } ++test; } } int main(){ #ifndef ONLINE_JUDGE freopen("oj0004.in", "r", stdin); freopen("oj0004.out", "w", stdout); #endif LL n; while(scanf("%lld",&n) != EOF){ check(n); } } #endif
相关推荐
浙江大学acm online judge 浙江大学acm online judge 浙江大学acm online judge
青岛大学开源 Online Judge | QQ群 496710125 。。。。。
百柱在线裁判用python解决算法问题
Online Judge系统(简称OJ)是一个在线的判题系统。用户可以在线提交程序多种程序(如C、C++、Pascal)源代码,系统对源代码进行编译和执行,并通过预先设计的测试数据来检验程序源代码的正确性。欢迎下载,内含源...
UVa Online Judge 10944 Accepted Code
scu online judge 源码展示 以及部分POJ题目分类
fzu online judge 的几道题,我的解题过程与思路,虽然都是很easy的题目,不过,重在参与嘛,哈哈
浙江大学Online Judge 1048题源码 自己写的,交流一下。
Online Judge Problem Code
c++在线考试系统,可以注册用户和管理进行出题等等,有多窗体的
基于Online Judge的C语言程序设计实验课教学改革研究.pdf
Online_Judge 拍: : leetcode: ://oj.leetcode.com/problems/ 工作杜: ://ac.jobdu.com
详细信息请查看:http://sonew.512j.com/ 请更改 config.php, config.ini 中数据库设置的相关信息。 数据库的导入请看 sql 目录下的文件 sql.sql。 后台程序在 bin 目录下。 后台源程序文件在 src 目录下。...
基于PHP,实现online judge 设计.
北京大学Online Judge ZOJ : 浙江大学Online Judge HDUOJ : 杭州电子科技大学Online Judge . HUSTOJ : 华中科技大学Online Judge UESTCOJ : 电子科技大学Online Judge NBOJ : 宁波工程学院Online Judge FZUOJ : 福州...
Online Judge Problem Code
在线测评地址,共享资源。地址正确。!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
leetcode 答案Online Judge 参考答案 简介 放置个人在线上解题系统所使用的程式码,仅供参考。 相关网站 网站 语系 中文+英文 中文 英文+中文 英文 英文 英文 英文 日文
阐述了Online Judge系统的功用,及它对训练奥赛选手所起的作用,详细探讨了在线Online Judge系统的实现。
Uri_Online_Judge UriOnlineJudge:Nv。 Iniciante-执行信息库。 :man::graduation_cap: #UriOnline判断ExercíciosResolvidos。 :woman::graduation_cap: 程序问题库: ## Lista deExercíciosAtéo Momento: ...