输入包含多组数据。
每组数据包括一个正整数n (1≤n<2^31)。
对应每组数据,如果n在2-16进制下存在回文数,则输出“Yes”;否则输出“No”。
32123<br/>17
Yes<br/>Yes
#include <stdlib.h> #include <stdio.h> #include <string.h> #define N /* */ //typedef struct { // //} ; char zhuan(int a) { char c; switch(a) { case 10: c='A'; break; case 11: c='B'; break; case 12: c='C'; break; case 13: c='D'; break; case 14: c='E'; break; case 15: c='F'; break; default: c=a+'0'; break; } return c; } int main() { int num; int r; char a[100]; int i; while((scanf("%d",&num))!=EOF) { int flag=0; for(int r=2; r<17; r++) { int n=num; i=0; while(n) { a[i++]=zhuan(n%r); n/=r; } flag=0; for(int j=0; j<(i)/2; j++) { if(a[j]!=a[i-j-1]) { flag=1; break; } } if(!flag)break; } if(!flag) { printf("Yes\n"); } else printf("No\n"); }; return 0; }
#include <stdio.h>int Switch(int a, int b, int *ar);int IsPilin(int *a, int len);int main(){int i;int len;int n;int a[10000];int res;int flag;while(scanf("%d", &n)!=EOF){flag = 0;for(i=2;i<17;i++){len = Switch(n, i, a);res = IsPilin(a, len);if(res==1){printf("Yes\n");flag = 1;break;}}if(flag==0){printf("No\n");}}return0;}int Switch(int a, int b, int *ar){int i = 0;while(a!=0){ar[i] = a % b;i++;a /= b;}return i;}intIsPilin(int*a, intlen){int low = 0;int high = len-1;int flag = 1;while(low<high){if(a[low]!=a[high]){flag = 0;break;}low++;high--;}return flag;}
def Switch(a, b): i = 0 ar = [] while a != 0: ar.append(a % b) i += 1 a //= b return ar def IsPilin(a, l): low = 0 high = l-1 flag = 1 while low<high: if a[low]!=a[high]: flag = 0 break low += 1 high -=1 return flag while True: flag = 0 try: n = int(input()) for i in range(2,17): lst = Switch(n, i) res = IsPilin(lst, len(lst)) if res==1: print("Yes") flag = 1 break if flag==0: print("No") except: break
#include<iostream> #include<string> #include<algorithm> using namespace std; bool check(string s){ if(s.size()<=1) return true; for(int i=0;i<s.size()/2;i++){ if(s[i]!=s[s.size()-i-1]) return false; } return true; } string tran(int n,int m){ string ret; int t; while(n!=0){ t=n%m; n/=m; if(t<10){ ret+=(t+'0'); } else{ ret+=(t-10+'A'); } } reverse(ret.begin(),ret.end()); return ret; } void fun(int n){ bool flag=false; for(int i=2;i<=16;i++){ if((flag=check(tran(n,i)))==true) break; } if(flag) cout<<"Yes"<<endl; else cout<<"No"<<endl; } int main(){ int n; while(cin>>n){ fun(n); } return 0; }
function huiwen(x){ let str = x + '' let newStr = '' for(let len = str.length, i = len - 1; i >= 0 ; i--) { newStr += str[i] } return newStr === str } while(line = readline()){ for (var l of line.split()){ var result = "No"; for (var i =2; i<=16;i++){ var str = parseInt(l).toString(i).split("") // var d = huiwen(str) if (huiwen(str)){ result = "Yes" } } console.log(result) } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); String result="No"; for(int i=2;i<=16;i++){ String str=Integer.toString(n,i); int flag=0; for(int j=0,k=str.length()-1;j<k;j++,k--){ if(str.charAt(j)!=str.charAt(k)) flag=1; } if(flag==0) result="Yes"; } System.out.println(result); } } }
import java.util.Scanner;
public class huiwenshu
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System. in );
int num[] = new int [32];
int temp,j,k;
boolean flag = true ;
while (sc.hasNext())
{
int n = sc.nextInt();
for ( int i = 2;i<=16;i++)
{
temp = n;
j = 0;
flag = true ;
do
{
num[j] = temp%i;
temp = temp/i;
j+=1;
}
while (temp!=0);
for (k = 0;k<=((j)/2);k++)
{
if (num[k] == num[j-k-1]) continue ;
else {flag = false ; break ;}
}
if (flag == true)) {System. out .println( "Yes" ); break ;}
}
if (flag == false ) System. out .println( "No" );
}
}
}
def baseN(num, b):
return ((num == 0) and "0") or (baseN(num // b, b).lstrip("0") + "0123456789abcdefghijklmnopqrstuvwxyz"[num % b])
while True:
try:
a,havaParo=int(input()),False
for i in range(2,17):
if baseN(a,i)==baseN(a,i)[::-1]:
havaParo=True
break
print("Yes" if havaParo else "No")
except:
break
#include (849)#include using namespace std; bool isok(int n) { for(int i=2;i<=16;i++) { vector vi; vi.clear(); int temp=n,flag=1; while(temp!=0) { vi.push_back(temp%i); temp/=i; } int k=0,j=vi.size()-1; while(k<j) { if(vi[k++]!=vi[j--]) { flag=0; break; } } if(flag) return 1; } return 0; } int main() { int n; while(scanf("%d",&n)!=EOF) { if(isok(n)) { printf("Yes\n"); } else printf("No\n"); } }
#include<stdio.h> int main() { int n; char s[100]; while(scanf("%d",&n)!=-1) { int i,j,k,m,flag; for(i=2;i<=16;i++) { m=n;k=0;flag=0; while(m) { if(m%i>=0&&m%i<=9) s[k++]=m%i+'0'; else s[k++]=m%i-10+'A'; m=m/i; } for(j=0;j<k;j++) if(s[j]!=s[--k]) flag=1; if(flag==0) break; } if(flag==0) printf("Yes\n"); else printf("No\n"); } return 0; }
#include <iostream> using namespace std; int ishuiwen(int n,int r){ int a[100]; int i=0; while(n){ a[i++]=n%r; n/=r; } for(int j=0;j<i;j++){ if(a[j]!=a[i-1-j]){ return 0; break; } } return 1; } int main(){ int n; while(cin>>n){ int flag=0; for(int i=2;i<=16;i++){ if(ishuiwen(n,i)==1){ flag=1; cout<<"Yes"<<endl; break; } } if(flag==0){ cout<<"No"<<endl; } } }
#include <stdio.h> #include <stdlib.h> #include <string.h> char jz_16[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; void change(int, int, char*);//进制转换,逆序存放 int is_palindrome(char*);//判断是否回文 int main() { int n; while(~scanf("%d", &n)) { int temp = 0; int i; for(i = 2; i < 17; i++) { char str[100] = {0}; change(n, i, str); temp = is_palindrome(str); if(temp) break; } if(temp) printf("Yes\n"); else printf("No\n"); } } void change(int n, int r, char str[]) { int i = 0; while(n) { str[i] = jz_16[n % r]; n /= r; i++; } } int is_palindrome(char str[]) { int len = strlen(str); for(int i = 0; i < len/2; i++) if(str[i] != str[len - i - 1]) return 0; return 1; }
#include <bits/stdc++.h> using namespace std; int toNum(char x){ if(x>='0'&&x<='9') return x-'0'; return x-'A'+10; } char toChar(int x){ if(x<10) return x+'0'; return x+'A'-10; } string cmp(int m, string s, int n){ int a[1001]; string b; for(unsigned int i=0;i<s.size();++i){ a[i]=toNum(s[i]); } for(unsigned int i=0;i<s.size();){ int temp=0,remain=0; for(unsigned int j=i;j<s.size();++j){ temp=(m*remain+a[j])%n; a[j]=(m*remain+a[j])/n; remain=temp; } b+=toChar(remain); while(a[i]==0) i++; } return b; } int main(){ string s; while(cin >>s){ int flag=0; for(int i=2;i<=16;++i){ string a = cmp(10,s,i); string b = cmp(10,s,i); reverse(b.begin(),b.end()); if(a==b){ flag=1; cout<<"Yes"<<endl; break; } } if(!flag) cout<<"No"<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; bool judge(char str[],int len){ for(int i=0;i<len/2;i++){ if(str[i]!=str[len-1-i]){ return false; } } return true; } bool fun(int n){ for(int i=2;i<=16;i++){ char result[10000]; int temp=n; int index=0; while(temp>0){ if(temp%i>=10){ result[index]=temp%i-10+'A'; }else{ result[index]=temp%i; } temp/=i; index++; } // printf("%d\n",judge(result,index)); if(judge(result,index))return true; } return false; } int main(){ int n; while(~scanf("%d",&n)){ fun(n)?printf("Yes\n"):printf("No\n"); } return 0; }
#include<stdio.h> #include<iostream> #include<string> #include<algorithm> using namespace std; int main(){ int n; while(~scanf("%d",&n)){ int i; int res=0; string s; int a[6]={'A','B','C','D','E','F'}; for(i=2;i<=16;i++){ int num=n; s.clear(); while(num!=0){ int m; //m记录余数 m=num%i; if(m<10){ s+=(m+'0'); } else{ s+=a[m-10]; } num=num/i; } //现在得到s是转化进制后的串 string h; h=s; reverse(h.begin(),h.end()); if(s==h){ res++; } } if(res>0){ printf("Yes\n"); } else{ printf("No\n"); } } }