1 条题解

  • 0
    @ 2024-12-24 9:54:33

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 210;
    int a[N], b[N], c[N], n;
    void convert(int a[], string s)
    {
    	int len = s.size();
    	for (int i = 0; i < len; i++)
    		if (s[i] >= '0' && s[i] <= '9') 
    			a[len-i-1] = s[i] - '0';
    		else
    			a[len-i-1] = s[i] - 'a' + 10;
    }
    
    int main()
    {
    	cin >> n;
    	string s1, s2;
    	cin >> s1 >> s2;
    	int len1 = s1.size();
    	int len2 = s2.size();
    	convert(a, s1);
    	convert(b, s2);
    	int len = max(len1, len2);
    	int t = 0;
    	for (int i = 0; i < len; i++)	
    	{
    		t += a[i] + b[i];
    		c[i] = t % n;
    		t /= n;
    	}
    	if (t > 0) c[len++] = t;
    	for (int i = len - 1; i >= 0; i--)
    		if (c[i] >= 10) cout << char(c[i] + 'a' - 10);
    		else cout << c[i];
    	return 0;
    }
    
    
    • 1

    信息

    ID
    1225
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者