原创 Dual Palindromes(ps:今天所有人的博客文章都打不开,有谁遇到过这个问题?)

2008-6-24 19:34 3256 3 4 分类: 软件与OS

steve今天考我的题目,写诗写出来了,不过没法提交oj验证。


原题如下:


Dual Palindromes
Mario Cruz (Colombia) & Hugo Rickeboer (Argentina)
A number that reads the same from right to left as when read from left to right is called a palindrome. The number 12321 is a palindrome; the number 77778 is not. Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome.


The number 21 (base 10) is not palindrome in base 10, but the number 21 (base 10) is, in fact, a palindrome in base 2 (10101).


Write a program that reads two numbers (expressed in base 10):


N (1 <= N <= 15)
S (0 < S < 10000)
and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10).
Solutions to this problem do not require manipulating integers larger than the standard 32 bits.


PROGRAM NAME: dualpal
INPUT FORMAT
A single line with space separated integers N and S.


SAMPLE INPUT (file dualpal.in)
3 25


OUTPUT FORMAT
N lines, each with a base 10 number that is palindromic when expressed in at least two of the bases 2..10. The numbers should be listed in order from smallest to largest.
SAMPLE OUTPUT (file dualpal.out)
26
27
28



我的输入输出格式直接就不管了。自己的代码如下:


#include<iostream>
using namespace std;
void get_jinzhi(unsigned int num,unsigned int base,int *array,int& point)
{
 unsigned int shang;
 point=0;
 while(base<=num)
 {
  shang=num/base;
  array[point]=num % base;
  num=shang;
  ++point;
 }
 array[point]=num;
}
bool decide(int* jinzhi,int point)
{
 bool flag="true";
 int j="0";
 while(j<=point/2)
 {
  if (jinzhi[j]==jinzhi[point-j])
   j++;
  else
  {
   flag=false;
   return flag;
  }
 }
 return flag;
}
int main(void)
{
 int jinzhi[21]={0};
 int point="0";
 unsigned int S="0",N=0;
 unsigned int rt_tms,number,base;


 cin>>N>>S;
 rt_tms=0;
 number=S;
 while (rt_tms<N)
 {
  ++number;
  for (base=2;base<=10;++base)
  {
   get_jinzhi(number,base,jinzhi,point);
   if (decide(jinzhi,point))
   {
    cout<<number<<endl;
    ++rt_tms;
    break;
   }
  }
 }
 return 0;
}

PARTNER CONTENT

文章评论1条评论)

登录后参与讨论

用户377235 2013-6-6 19:36

错了? two or more number bases (2 <= base <= 10). 这句话估计你没看到 跟我第一次做的一样,怎么都过不了oj 回头发现这句话
相关推荐阅读
用户146369 2010-05-11 20:06
几个中兴华为3G模块比较
注:X表示资料中未提及。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />参数MC86...
用户146369 2010-05-11 17:55
关于移动通信的一些基本概念和3G(最近学习笔记,不一定对)
名词解释:IMT-2000:国际移动通信2000                   工作在2000MHz,最高2000kbit/s(至少:室内2Mbit/s,室外步行384kbit/s,室外车载14...
用户146369 2010-03-15 16:09
小鲍子回来了
好久没来了,没来的这段时间主要是上课,跟师兄后面做嵌入式软件,然后陆续的出差。现在刚接了一个网络摄像头的新项目,搜资料一不小心搜到这里,突然想回来了。接下来的日子,与EDN一起进步...
用户146369 2009-04-20 16:08
备忘Mfile:不过新版本的WINAVR已经是好的了
AVR-GCC“needed by 'xx.elf'”编译错误解决方案初次使用AVR-GCC/WINavr,使用VC++6.0做IDE,尝试编译程序时候总是出现如下错误:<?xml:namesp...
用户146369 2009-03-15 16:08
TIP:mega128 and max485
大致情况:M128连接MAX485,再通过485转232转换器连接到上位PC机。出现问题:M128与上位机的通讯能发能收,但收发的数据通通不正确。M128接收的错误数据多是255,发送的错误数据多出现...
用户146369 2009-03-04 17:01
ADI的客服气死我啦!
本来周围人就告诫我说ADI的样片难弄,可惜我这次偏偏要用到几种ADI的片子,没法子硬着头皮去申请。登陆后,网上选好了我要的样片;结果跳出来的网页ADI的客服要我们打电话过去,说是申请流程的一部分。最让...
EE直播间
更多
我要评论
1
3
关闭 站长推荐上一条 /3 下一条