zoukankan      html  css  js  c++  java
  • SPOJ 362 Ignore the Garbage 转7进制+简单大数除法

    显然正着倒着看仍然是数字的只有7个数:0,1,2,5,6,8,9

    所以就是用这7个数组合成不同的数。

    将n转换成7进制,对应位输出即可。

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <algorithm>
    
    using namespace std;
    
    const char num[] = "0125986";
    const int MAXN = 1010;
    const int BASE = 7;
    
    char str[MAXN];
    int a[MAXN];
    int b[MAXN];
    int ans[MAXN];
    int cnt, len;
    
    bool check()
    {
        for ( int i = 0; i < len; ++i )
            if ( a[i] ) return true;
        return false;
    }
    
    void Mod()
    {
        int tmp = 0;
        for ( int i = 0; i < len; ++i )
        {
            tmp = tmp * 10 + a[i];
            b[i] = tmp / BASE;
            tmp %= BASE;
        }
        ans[cnt++] = tmp;
    
        int i = 0, j;
        while ( i < len && b[i] == 0 ) ++i;
        for ( j = 0; i < len; ++i, ++j )
            a[j] = b[i];
        len = j;
    
        return;
    }
    
    int main()
    {
        int T;
        scanf( "%d", &T );
        while ( T-- )
        {
            scanf( "%s", str );
            len = strlen(str);
            cnt = 0;
            for ( int i = 0; i < len; ++i )
                a[i] = str[i] - '0';
    
            while ( check() ) Mod();
    
            for ( int i = 0; i < cnt; ++i )
                putchar( num[ ans[i] ] );
    
            puts("");
        }
        return 0;
    }
  • 相关阅读:
    DBHelper
    jsTree使用
    爬虫系列之Scrapy框架
    Mongodb安装
    爬虫系列之mongodb
    爬虫学习目录
    爬虫之selenium模块
    爬虫简介与requests模块
    爬虫数据解析的三方式
    线程相关
  • 原文地址:https://www.cnblogs.com/GBRgbr/p/3248570.html
Copyright © 2011-2022 走看看