zoukankan      html  css  js  c++  java
  • ZOJ Problem Set–1078 Palindrom Numbers

    Time Limit: 2 Seconds      Memory Limit: 65536 KB


    Statement of the Problem

    We say that a number is a palindrom if it is the sane when read from left to right or from right to left. For example, the number 75457 is a palindrom.

    Of course, the property depends on the basis in which is number is represented. The number 17 is not a palindrom in base 10, but its representation in base 2 (10001) is a palindrom.

    The objective of this problem is to verify if a set of given numbers are palindroms in any basis from 2 to 16.

    Input Format

    Several integer numbers comprise the input. Each number 0 < n < 50000 is given in decimal basis in a separate line. The input ends with a zero.

    Output Format

    Your program must print the message Number i is palindrom in basis where I is the given number, followed by the basis where the representation of the number is a palindrom. If the number is not a palindrom in any basis between 2 and 16, your program must print the message Number i is not palindrom.

    Sample Input

    17
    19
    0

    Sample Output

    Number 17 is palindrom in basis 2 4 16
    Number 19 is not a palindrom


    Source: South America 2001

      1: #include<iostream>
    
      2: #include<vector>
    
      3: #include<set>
    
      4: #include<algorithm>
    
      5: using namespace std;
    
      6: vector<int>& transfor(int num, int basis)
    
      7: {
    
      8:   vector<int> *vecResult = new vector<int>();
    
      9:   while(num)
    
     10:   {
    
     11:     (*vecResult).push_back(num%basis);
    
     12:     num /= basis;
    
     13:   }
    
     14:   return *vecResult;
    
     15: }
    
     16: int main(void)
    
     17: {
    
     18:   int num;
    
     19:   while(cin>>num && num)
    
     20:   {
    
     21:     set<int> s;
    
     22:     for(int i = 2; i <= 16;i++)
    
     23:     {
    
     24:       vector<int> temp1 = transfor(num, i);
    
     25:       vector<int> temp2(temp1);
    
     26:       reverse(temp2.begin(), temp2.end());
    
     27:       if(temp1 == temp2)
    
     28:       {
    
     29:         s.insert(i);
    
     30:       }
    
     31:         
    
     32:     }
    
     33:     if(s.size() > 0)
    
     34:     {
    
     35:       cout<<"Number "<<num<<" is palindrom in basis";
    
     36:       for(set<int>::iterator it = s.begin(); it != s.end(); it++)
    
     37:         cout<<" "<<*it;
    
     38:       cout<<endl;
    
     39:     }
    
     40:     else
    
     41:     {
    
     42:       cout<<"Number "<<num<<" is not a palindrom"<<endl;
    
     43:     }
    
     44:   }
    
     45:   return 0;
    
     46: }
  • 相关阅读:
    sublime text 4 vim 插件配置
    ssh-keygen 的使用
    distribution transaction solution
    bilibili 大数据 视频下载 you-get
    Deepin 20.2.1 安装 MS SQL 2019 容器版本
    【转】使用Linux下Docker部署MSSQL并加载主机目录下的数据库
    【转】You Can Now Use OneDrive in Linux Natively Thanks to Insync
    dotnet 诊断工具安装命令
    Linux 使用 xrandr 设置屏幕分辨率
    【转】CentOS 7.9 2009 ISO 官方原版镜像下载
  • 原文地址:https://www.cnblogs.com/malloc/p/2491583.html
Copyright © 2011-2022 走看看