首页 > 代码库 > Dual Palindromes

Dual Palindromes

链接

分析:直接暴力求解,傻逼题

技术分享
 1 /*
 2     ID:wanghan
 3     PROB:dualpal
 4     LANG:C++
 5 */
 6 #include "iostream"
 7 #include "cstdio"
 8 #include "cstring"
 9 #include "string"
10 using namespace std;
11 string Rev(int num,int b){
12     string t="";
13     while(num){
14         int z=num%b;
15         if(z>=10)
16             t+=(z-10)+A;
17         else
18             t+=z+0;
19         num/=b;
20     }
21     int len=t.length();
22     int i=0,j=len-1;
23     while(i<j){
24         swap(t[i],t[j]);
25         i++,j--;
26     }
27     return t;
28 }
29 bool judge(string s,int i,int j){
30     while(i<j){
31         if(s[i]==s[j]){
32             i++,j--;
33         }else{
34             return false;
35         }
36     }
37     return true;
38 }
39 int n,s;
40 int main()
41 {
42     freopen("dualpal.in", "r", stdin);  
43     freopen("dualpal.out", "w", stdout);
44     cin>>n>>s;
45     int cnt=0;
46     //int flag=0;
47     while(1){
48         ++s;
49         int tt=0,flag=0;
50         for(int i=2;i<=10;i++){
51             string t=Rev(s,i);
52             int len=t.length()-1;
53             if(judge(t,0,len)){
54                 tt++;
55             }
56             if(tt>=2){
57                 flag=1; break;
58             }
59         }
60         if(flag){
61             cnt++;
62             cout<<s<<endl;
63         }
64         if(cnt==n)  break;
65     }
66 }
View Code

 

Dual Palindromes