zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM :1008: 华科版C语言程序设计教程(第二版)习题6.14

    Problem Description

     输入一个八进制的字符串,将它转换成等价的十进制字符串,用pringf的%s格式输出。

    Input

     首先输入一个正整数t,表示有t组测试数据(1<= t <= 10010)。

    接下来t行,每行一个字符串,表示一个八进制整数(这个整数不超过20位)。

    Output

     对于每个测试数据,输出相应的十进制字符串。每个字符串一行。

    Sample Input

    1
    1732
    

    Sample Output

    986
    

    HINT

     注意:给的八进制数可能很大,用long long

    #include<stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    long long mishu(int j)
    {
        long long res = 1;
        for(;j>0;j--)
        {
            res *= 8;
        }
        return res;
    }
    
    int  main()
    {
        int i,j,k,m;
        long long n;
        while(scanf("%d",&m)!=EOF)
        {
            for(k=0;k<m;k++)
            {
                n=0;
                char s[40];
                scanf("%s",s);
                for(i=strlen(s)-1,j=0;i>=0;i--,j++)
                {
                    n += (s[i]-'0')*mishu(j);
                }
                printf("%lld
    ",n);    
            }        
        }    
        return 1;
    }
  • 相关阅读:
    为什么需要Docker?
    shiro原理
    java面对对象
    mysql面试题
    spring boot +thymeleaf+ mybatis
    mysql语句级sql
    spring boot+spring cloud面试笔记
    Docker-compose配置
    Docker compose命令的使用
    Dockerfile操作命令说明
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4159542.html
Copyright © 2011-2022 走看看