P1590 失踪的7

P1590 失踪的7
进制转换的题目,如果把一个10进制的数当成9进制,相当于没有9这个数字,题目失踪了7,但是无所谓。如果当前的大于7,它就跳过了一个数字,向左移动1位。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<cstring>
 8 #define inf 2147483647
 9 #define For(i,a,b) for(register long long i=a;i<=b;i++)
10 #define p(a) putchar(a)
11 #define g() getchar()
12 //by war
13 //2017.10.23
14 using namespace std;
15 long long t,n;
16 char a[100000];
17 long long len;
18 long long P[10000];
19 long long ans;
20 void in(long long &x)
21 {
22     long long y=1;
23     char c=g();x=0;
24     while(c<'0'||c>'9')
25     {
26     if(c=='-')
27     y=-1;
28     c=g();
29     }
30     while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
31     x*=y;
32 }
33 void o(long long x)
34 {
35     if(x<0)
36     {
37         p('-');
38         x=-x;
39     }
40     if(x>9)o(x/10);
41     p(x%10+'0');
42 }
43 int main()
44 {
45     in(t);
46     P[0]=1;
47     For(i,1,15)
48     P[i]=P[i-1]*9;
49     while(t--)
50     {
51     ans=0;
52     cin>>a;
53     len=strlen(a);
54     For(i,0,len-1)
55     {
56         if(a[i]>'7')
57         a[i]-=1;
58         ans+=(a[i]-'0')*P[len-1-i];
59     }
60     o(ans),p('\n');
61     }
62     
63      return 0;
64 }

 

posted @ 2017-10-24 07:49  WeiAR  阅读(481)  评论(0编辑  收藏  举报