• 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 500
    
    Keep up the good work!
    Thanks for your submission!

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    傅里叶变换相关公式
    Java中的IO流
    oracle sqlplus 命令行中创建存储过程
    Redis 缓存数据库的使用场景
    Java 数值格式化类-NumberFormat
    Idea_类注释、属性注释、方法注释
    博客·HelloWorld
    【4】Django 创建第一个模块应用
    【3】Django创建第一个项目
    理解面向对象三大特征与魔法方法?
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4873700.html
Copyright © 2020-2023  润新知