多进制高精加那错啦??

回复帖子

@溪水瑶 2019-08-14 19:41 回复

我感觉无懈可击呢

#include<bits/stdc++.h>
using namespace std;
int n,d[210],e[210];
char c[37]={'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z'};
char a[210],b[210];
int main(){
    cin>>n>>a>>b;
    int lena=strlen(a),lenb=strlen(b);
    for(int i=0;i<lenb;i++)
        if(b[i]>='a'&&b[i]<='z')
            d[i]=b[i]-'a'+10;
        else d[i]=b[i]-'0'; 
    for(int i=0;i<lena;i++)
        if(a[i]>='a'&&b[i]<='z')
            e[i]=a[i]-'a'+10;
        else e[i]=a[i]-'0';
    int y=0;
    reverse(d,d+lenb);reverse(e,e+lena);
    int i=0;
    for(;i<lena||i<lenb;i++){
        int x=(d[i]+e[i])%n;
        if(d[i]+e[i]>=n)e[i+1]++;
        b[i]=c[x];
    }
    if(d[i]+e[i]>=n)cout<<1;
    b[i]=c[(d[i]+e[i])%n];
    for(int j=i-1;j>=0;j--)
        cout<<b[j];
    return 0;
}
@yu__xuan 2019-08-14 19:59 回复 举报

@溪水瑶

#include<bits/stdc++.h>
using namespace std;
int n,d[210],e[210];
char c[37]={'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z'};
char a[210],b[210];
int main(){
    cin>>n>>a>>b;
    int lena=strlen(a),lenb=strlen(b);
    for(int i=0;i<lenb;i++)
        if(b[i]>='a'&&b[i]<='z')
            d[i]=b[i]-'a'+10;
        else d[i]=b[i]-'0'; 
    for(int i=0;i<lena;i++)
        if(a[i]>='a'&&b[i]<='z')
            e[i]=a[i]-'a'+10;
        else e[i]=a[i]-'0';
    int y=0;
    reverse(d,d+lenb);reverse(e,e+lena);
    int i=0;
    for(;i<lena||i<lenb;i++){
        int x=(d[i]+e[i])%n;
        if(d[i]+e[i]>=n)e[i+1]++;
        b[i]=c[x];
    }
    i--;
    if(d[i]+e[i]>=n)cout<<1;
    b[i]=c[(d[i]+e[i])%n];
    for(int j=i;j>=0;j--)
        cout<<b[j];
    return 0;
}
反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。