首页 > 代码库 > USACO dualpal
USACO dualpal
/* ID:kevin_s1 PROG:dualpal LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <vector> using namespace std; int N,S; vector<int> result; bool isPalindromic(string num){ bool flag = true; int len = num.length(); for(int i = 0; i <= len/2; i++){ if(num[i] != num[len - i - 1]){ flag = false; } } if(num[0] == ‘0‘ || num[len - 1] == ‘0‘) flag = false; return flag; } string trans(int num,int base){ string str; while(num > 0){ str += num % base + ‘0‘; num = num / base; } reverse(str.begin(),str.end()); return str; } int main(){ freopen("dualpal.in","r",stdin); freopen("dualpal.out","w",stdout); cin>>N>>S; int index = 0; for(int i = S + 1; index < N; i++){ int x = i; int count = 0; for(int base = 2; base <= 10; base++){ string num = trans(x,base); if(isPalindromic(num)){ count++; } } if(count >= 2){ index++; result.push_back(x); } } vector<int>::iterator iter = result.begin(); for(;iter != result.end();iter++){ cout<<*iter<<endl; } return 0; }
提交结果:
USER: Kevin Samuel [kevin_s1] TASK: dualpal LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.000 secs, 3504 KB] Test 2: TEST OK [0.000 secs, 3504 KB] Test 3: TEST OK [0.027 secs, 3504 KB] Test 4: TEST OK [0.000 secs, 3504 KB] Test 5: TEST OK [0.000 secs, 3504 KB] Test 6: TEST OK [0.014 secs, 3504 KB] Test 7: TEST OK [0.003 secs, 3504 KB] All tests OK.YOUR PROGRAM (‘dualpal‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.
Here are the test data inputs:
------- test 1 ---- 5 1 ------- test 2 ---- 9 10 ------- test 3 ---- 15 9900 ------- test 4 ---- 10 90 ------- test 5 ---- 12 125 ------- test 6 ---- 12 1900 ------- test 7 ---- 8 500Keep up the good work!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。