3 条题解

  • 1
    @ 2023-11-30 12:52:40
    #include <bits/stdc++.h>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    int a[1005], b[1005], c[1005];
    char s1[1005], s2[1005];
    int main()
    {
    	int n;
    	cin >> n >> s1 >> s2;
    	int l = strlen(s1);
    	for (int i = 0; i < l; i++)
    		if (s1[i] >= 'a' && s1[i] <= 'z')
    			a[l - i] = s1[i] - 87;
    		else
    			a[l - i] = s1[i] - 48;
    	l = strlen(s2);
    	for (int i = 0; i < l; i++)
    		if (s2[i] >= 'a' && s2[i] <= 'z')
    			b[l - i] = s2[i] - 87;
    		else
    			b[l - i] = s2[i] - 48;
    	l = max(strlen(s1), strlen(s2));
    	for (int i = 1; i <= l; i++)
    	{
    		c[i] += a[i] + b[i];
    		c[i + 1] = c[i] / n;
    		c[i] %= n;
    	}
    	if (c[l + 1])
    		l++;
    	for (int i = l; i > 0; i--)
    		if (c[i] > 9)
    			cout << char(c[i] + 87);
    		else
    			cout << c[i];
    	return 0;
    }
    
    • 0

      这题只要注意9以上的数字的处理就行了。

      上AC代码

      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e3+10;
      long long n,a[N],b[N],c[N];
      int main(){
      #define int long long
      	char s1[N],s2[N];
      	cin>>n>>s1>>s2;
      	int l=strlen(s1),r=strlen(s2);int s=max(l,r);
      	for(int i=0;i<l;i++){
      		if(s1[i]>='a'&&s1[i]<='z')a[l-i]=s1[i]-87;
      		else a[l-i]=s1[i]-48;
      	}
      	for(int i=0;i<r;i++){
      		if(s2[i]>='a'&&s2[i]<='z')b[r-i]=s2[i]-87;
      		else b[r-i]=s2[i]-48;
      	}
      	for(int i=0;i<=s;i++){
      		c[i]+=a[i]+b[i];
      		c[i+1]+=c[i]/n;
      		c[i]%=n;
      	}
      	if(c[s+1]){
      		s++;
      	}
      	for(int i=s;i>0;i--){
      		if(c[i]>9)cout<<char(c[i]+87);
      		else cout<<c[i];
      	}
      	return 0;
      }
      

      点个赞吧,球球了。

      • 0
        @ 2022-1-8 16:41:00
        /*****************************************
        备注:
        ******************************************/
        #include <queue>
        #include <math.h>
        #include <stack>
        #include <stdio.h>
        #include <iostream>
        #include <vector>
        #include <iomanip>
        #include <string.h>
        #include <algorithm>
        using namespace std;
        #define LL long long
        const int N = 1e5 + 10;
        const int INF = 0x3f3f3f3f;
        int a[1005], b[1005], c[1005];
        char s1[1005], s2[1005];
        int main()
        {
        	int n;
        	cin >> n >> s1 >> s2;
        	int l = strlen(s1);
        	for (int i = 0; i < l; i++)
        		if (s1[i] >= 'a' && s1[i] <= 'z')
        			a[l - i] = s1[i] - 87;
        		else
        			a[l - i] = s1[i] - 48;
        	l = strlen(s2);
        	for (int i = 0; i < l; i++)
        		if (s2[i] >= 'a' && s2[i] <= 'z')
        			b[l - i] = s2[i] - 87;
        		else
        			b[l - i] = s2[i] - 48;
        	l = max(strlen(s1), strlen(s2));
        	for (int i = 1; i <= l; i++)
        	{
        		c[i] += a[i] + b[i];
        		c[i + 1] = c[i] / n;
        		c[i] %= n;
        	}
        	if (c[l + 1])
        		l++;
        	for (int i = l; i > 0; i--)
        		if (c[i] > 9)
        			cout << char(c[i] + 87);
        		else
        			cout << c[i];
        	return 0;
        }
        
        • 1

        信息

        ID
        1193
        时间
        1000ms
        内存
        128MiB
        难度
        5
        标签
        递交数
        137
        已通过
        54
        上传者