USACO dualpal

37 篇文章 0 订阅
/*
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 500
Keep up the good work!
Thanks for your submission!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值