一个典型十进制数字的转换的问题,是如何利用C语言编程的技术解决的?

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 <>,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

输入的括号内为进制数,括号前则为该进制的数字串

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LINE_MAX 100
#define DATA_LEN 1000

typedef long unsigned  uint_32;
typedef unsigned char uint_8;

char data[LINE_MAX][DATA_LEN];

//分割数据,src 传递要分割的原数据,并保存分割后的数字数据串,base保存进制
char split_data(char *src,char *base)
{
    char *p = NULL;
    char *q = NULL;

    if(!src || !base)
    {
        printf("输入数据异常\n");
        return 0;
    }

    if((p = strchr(src,'(')) == NULL)
    {
       printf("解析数据异常,未查找到(\n");
       return 0; 
    }
    else
    {
        *p = '\0';
        p++;
        q = p;
        if((p = strchr(p,')')) == NULL)
        {
            printf("解析数据异常,未查找到)\n");
            return 0; 
        }

        *p = '\0';
        *base = atoi(q);

        printf("解析后数据%s,base:%d\n",src,*base);
        if(*base > 10 || *base < 0)
        {
            printf("解析数据异常,解析的进制不符合要求\n");
            return 0; 
        }

        //printf("解析后数据%s,base:%d\n",src,*base);
        return 1;
    }

}

uint_32 calculate(void)
{
    uint_32 sum = 0;
    char inbuf[4] = {'\0'};
    char cnt = 0;
    char i = 0;
    char base = 0;

    while(1)
    {
        printf("请输入要计算的数量,小于100:");
        fflush(stdin);
        if((cnt = (atoi(fgets(inbuf,4,stdin)))) > LINE_MAX)
        {
            printf("输入错误,超出最大数量\n");

            continue;
        }

        break;
    }

    for(i = 0; i < cnt; i ++)
    {
        while(1)
        {
            printf("输入第[%d]组数据:",i);
            scanf("%s",data[i]);

            if(!split_data(data[i],&base))
            {
                printf("输入的数据不合法,请重新输入改行数据\n");
                //return 0;
            }
            else
            {
                break;
            }
        }

        sum += strtoul(data[i],NULL,base);      
        //printf("计算过程sum:%d\n",sum);   
    }

    return sum;

}

int main()
{
    uint_32 sum = 0;

    sum = calculate();
    puts("********************************");
    printf("计算总和为%d\n",sum);
    puts("********************************");
    system("pause");

    return 0;
}

运算结果:图片说明