HDU 2106 decimal system(进制转换+模拟)

By | 05月14日
Advertisement

decimal system

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4367 Accepted Submission(s): 2476

Problem Description

As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12.
But after learning <<The Principle Of Computer>>,we know that the computer will do the calculation as the following steps:
1 computer change the 3 into binary formality like 11;
2 computer change the 9 into binary formality like 1001;
3 computer plus the two number and get the result 1100;
4 computer change the result into decimal formality like 12;
5 computer export the result;

In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system.

Input

There will be several cases. The first line of each case contains one integers N, and N means there will be N numbers to import, then there will be N numbers at the next N lines, each line contains a number with such form : X1….Xn.(Y), and 0<=Xi<Y, 1<Y<=10. I promise you that the sum will not exceed the 100000000, and there will be at most 100 cases and the 0<N<=1000.

Output

There is only one line output case for each input case, which is the sum of all the number. The sum must be expressed using the decimal system.

Sample Input

3 1(2) 2(3) 3(4) 4 11(10) 11(2) 11(3) 11(4)

Sample Output

6 23

Source

HDU 2007-6 Programming Contest

题解:进制转换+模拟

AC代码:

#include<iostream>
#include<memory.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<list>
#include<map>
#include<algorithm>
typedef long long LL;
using namespace std;
int f(int m,int n)
{
    int sum=0;
    int p=1;
    while(m)
    {
        sum+=(m%10)*p;
        p=p*n;
        m=m/10;
    }
    return sum;
}
int main()
{
    int n,x,y,sum;
    while(cin>>n)
    {
        sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d(%d)",&x,&y);
            sum+=f(x,y);
        }
        printf("%d\n",sum);
    }
    return 0;
}

Similar Posts:

  • hdu 2106 decimal system (数学)

    点击打开链接 //没想到还可以这样来,用两个字符把括号吸收, #include"stdio.h" #include"math.h" int main() { int k,n; int i; char s1,s2; int a[110],b[110]; int sum; while(scanf("%d",&n)!=EOF&&n) { sum=0; for(i=0;i<n;i++) { scanf("%d&qu

  • HDU 2031 进制转换(模拟)

    进制转换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 39861 Accepted Submission(s): 21826 Problem Description 输入一个十进制数N,将它转换成R进制数输出. Input 输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R<>10

  • HDU 2031 进制转换(进制转换)

    Description 输入一个十进制数N,将它转换成R进制数输出 Input 输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R<>10) Output 为每个测试实例输出转换后的数,每个输出占一行.如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等) Sample Input 7 2 23 12 -4 3 Sample Output 111 1B -11 Solution 进制转换,每次将N%R压进栈中,把N R进

  • HDU 1390 Binary Numbers【进制转换】

    /* 中文题目 二进制数 中文翻译-大意 求解一个数的二进制数中所有的1的位置 解题思路:将给定的数转换成二进制,存入数组中,再控制一下格式,输出所有是1的位置即可. 关键点:格式控制,进制转换 解题人:lingnichong 解题时间:2014-08-26 20:55:43 解题体会:学会了一种格式控制 */ Binary Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot

  • 进制转换:将十进制转换为十六进制输出

    进制转换可以用递归来做,其实用递归呢也是用堆栈来实现的 下面的这段程序是用堆栈实现的:并通过测试 #include <stdio.h> #include <malloc.h> #define STACK_INIT_SIZE 100 #define STACK_INCREMENT 10 #define SElemtype int typedef struct { SElemtype *top; SElemtype *base; int stacksize; }SqStack; typ

  • Python数据结构与算法 7栈的应用之进制转换

    Converting Decimal Numbers to Binary Numbers 栈的应用:进制转换 In your study of computer science, you have probably been exposed inone way or another to the idea of a binary number. Binary representation is importantin computer science since all values store

  • C#进制转换操作(三)之16进制操作

    一.字符串和16进制字符串互转 1.字符串转16进制字符串 /// <summary> /// 字符串转Hex,方法1使用Convert.ToString(byte, 16) /// </summary> /// <param name="str"></param> /// <returns></returns> public static string StringToHex(string str) { Stri

  • Java:进制转换

    进制转换是常常需要的一种数据处理,在java中的一些类中封装了具有转换功能的方法,这个不做介绍.其实,进制之间的转化是通过先位异或&,再位移动>>>的方式实现的. 例如,对于一个十进制的整数而言,Int整型占4个字节,每一个字节为8个bit位,所以整型数据有32位bit.将整型转换为二进制,需要先将基数num=num&1,然后将32位bit右移>>>1位,直到num!=0条件不满足即可 将整型转换为八进制,需要先将基数num=num&7,然后将3

  • java中Integer包装类的详细讲解(java二进制操作,所有进制转换)

    程序员都很懒,你懂的! 今天为大家分享的是Integer这个包装类.在现实开发中,我们往往需要操作Integer,或者各种进制的转换等等.我今天就为大家详细讲解一下Integer的使用吧.看代码: package com.herman.test; public class IntegerTest { public static void main(String[] args) { System.out.println("Integer中的常量***************************

  • java进制转换---算法版

    /* @src http://eric-619.iteye.com/blog/693665 *公式自己总结吧,很简单了 * java进制转换代码实例(算法实现) * 2.8.10.16两两转换 * 二进制: 0-1 * 八进制: 0-7 * 十进制: 0-9 * 十六进制:0-9 a-f(A表示10,而F表示15) (十六进制一般以ox或Ox开头) * * */ public class SuanFa { public static void main(String[] args) { int

Tags: