上下颠倒,数字反过来仍是有效数字的有0,1,2,5,6,8,9,反过来就是0,1,2,5,9,8,6.所以这样组成的有效数字是:
0,1,2,5,9,8,6
01,11,21,51,91,81,61
02,12,22,52,92,82,62
05,15,25,,55,95,,85,65
。。。。。
。。。。。
001,101,201,501,901,801,601
可以发现每7个一个循环,同时每个数第一位是0,1,2,5,9,8,6,然后第二个数是7个1,然后是7个2,7个5,,,,就会想到和7进制有关。(可惜方法不是我想到的)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define MAXN 50010
using namespace std;
int num[210],len,ans[500],temp;
int digit[]= {0,1,2,5,9,8,6};
bool check()
{
for(int i=0; i<len; i++)
if(num[i])
return true;
return false ;
}
int main()
{
//freopen("in.txt","r",stdin);
int cas;
char str[210];
cin>>cas;
getchar();
while(cas--)
{
memset(num,0,sizeof(num));
memset(ans,0,sizeof(ans));
cin>>str;
len=strlen(str);
for(int i=0; str[i]!='\0'; i++)
num[i]=str[i]-'0';
temp=0;
int t=0;
while(check())
{
t=0;
for(int i=0; i<len; i++)
{
t=t*10+num[i];
num[i]=t/7;
t%=7;
}
ans[temp++]=t;
}
for(int i=0; i<temp; i++)
cout<<digit[ans[i]];
cout<<endl;
}
return 0;
}