zoukankan      html  css  js  c++  java
  • 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('
    ');
    61     }
    62     
    63      return 0;
    64 }
  • 相关阅读:
    SDN概述
    Linux企业运维人员必备150个命令汇总
    自动化运维工具puppet详解(二)
    自动化运维工具puppet详解(一)
    自动化运维工具[ansible详解三]
    ansible 常用模块
    自动化运维工具【ansible详解 二】
    A. Cinema Line
    A. Wrong Subtraction
    A. The number of positions
  • 原文地址:https://www.cnblogs.com/war1111/p/7721730.html
Copyright © 2011-2022 走看看