c++ decimal system

decimal system

HDU 2007-6 Programming Contest
c++ decimal system_第1张图片

这个是数字转换的问题

写的有点麻烦,请见谅

#include
#include 
#include 
using namespace std;
int main()
{
    int n;
    char str[1000], ch[20], num[1000];
    while (scanf_s("%d", &n) != EOF)
    {
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            str[0] = '\0';
            ch[0] = '\0';
            num[0] = '\0';
            cin >> str;
            int length = strlen(str);
            int startIndex = -1, index = -1;
            for (int j = 0; j < length - 1; j++)
            {
                if (str[j] == '(')
                {
                    startIndex = j + 1;
                    num[j] = '\0';
                }
                if (startIndex != -1)
                {
                    index++;
                    if (str[j + 1] == ')')
                    {
                        ch[index] = '\0';
                        break;
                    }
                    ch[index] = str[j + 1];
                }
                else
                {
                    num[j] = str[j];
                }
            }

            int lengthNum = strlen(num);
            int lengthCh = strlen(ch);
            int quan = 0;
            for (int q = 0; q < lengthCh; q++)
            {
                quan += (ch[q] - 48) * (int)pow(10, lengthCh - q - 1);
            }

            for (int p = 0; p < lengthNum; p++)
            {
                sum += (num[p] - 48) * (int)pow(quan, lengthNum - p - 1);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

  • decimal system
      • 这个是数字转换的问题

你可能感兴趣的:(c++,c++,HDU)