Home > Old Blog Posts > USACO 1.2.5 Dual Palindromes

USACO 1.2.5 Dual Palindromes


用结构化编程做上一题的话,做这一题就很爽

函数都有现成的了

代码:

/*
ID: dementr1
PROG: dualpal
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin(“dualpal.in”);
ofstream fout(“dualpal.out”);
bool judge(int n,int base)
{
int tmp=n,t[40],num=0,i;
while(tmp>0)
{
t[num++]=tmp%base;
tmp=tmp/base;
}
for(i=0;i<=(int)num/2;i++) if(t[num-i-1]!=t[i]) return false;
return true;
}

int main()
{
int N,start,i;
fin>>N>>start;
int count=0;
while(count<N)
{
start++;
int counter=0;
for(i=2;i<=10;i++) if(judge(start,i)) counter++;
if(counter>=2)
{
count++;
fout<<start<<endl;
}
}
return 0;
}

Categories: Old Blog Posts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: