USACO 1.2.5 Dual Palindromes

来源:互联网 发布:电视直播软件tv版排行 编辑:程序博客网 时间:2024/05/14 16:08

/*
PROG: dualpal
LANG: C++
*/

#include 
<iostream>
#include 
<fstream>
#include 
<string>
#include 
<cmath>
using namespace std;
ifstream fin(
"dualpal.in");
ofstream fout(
"dualpal.out");
int n,s;
inline 
bool hui (int k,int b)
{
    
int a[32],l=0;
    
while( k>0)
    
{
        l
++;
        a[l]
=k%b;
        k
/=b;
    }

    
int i=1;
    
while( a[i]==a[l])
        i
++,l--;
    
if( i>=l) return true;
        
else return false ;
}

inline 
bool check(int k)
{
    
int p=0;
    
for(int i=2;p<2&&i<=10;i++)
        
if( hui( k , i) ) p++;
    
return (p==2);
}

int main()
{
    fin
>>n>>s;
    
for(int i=s+1;n>0;i++)
        
if( check(i) ) fout<<i<<endl,n--;
    
return 0;
}


Compiling...
Compile: OK

Executing...
      Test 
1: TEST OK [0 secs]
      Test 
2: TEST OK [0.004 secs]
      Test 
3: TEST OK [0.012 secs]
      Test 
4: TEST OK [0.004 secs]
      Test 
5: TEST OK [0 secs]
      Test 
6: TEST OK [0.004 secs]
      Test 
7: TEST OK [0.004 secs]

All tests OK.
YOUR PROGRAM (
'dualpal') WORKED FIRST TIME!
 That
's fantastic -- and a rare thing. 
Please accept these special automated congratulations. 
 
原创粉丝点击