问题标题: 酷町堂:7021,急,WA80分,2和6测试点错了,可加悬赏(时限今天)

0
0
已解决
任泓涛
任泓涛
资深守护
资深守护
  • #include <bits/stdc++.h> using namespace std; string n,m; int p,q; long long t,h; string s="0123456789abcdefghijklmnopqrstuvwxyz"; int main(){ cin>>n>>m>>p>>q; if(p==1){ long long cnt=1; for(int i=0;i<n.size();i++){ if(n[i]<='9'){ t+=(n[i]-'0')*cnt; }else{ t+=(n[i]-87)*cnt; } cnt*=q; } for(int i=2;i<=35;i++){ string pos=m; h=0; cnt=1; for(int j=pos.size()-1;j>=0;j--){ if(pos[j]<='9'){ h+=(pos[j]-'0')*cnt; }else{ h+=(pos[j]-87)*cnt; } cnt*=i; } if(h==t){ cout<<i; return 0; }else if(h>t){ break; } } }else{ long long cnt=1; for(int i=0;i<m.size();i++){ if(m[i]<='9'){ t+=(m[i]-'0')*cnt; }else{ t+=(m[i]-87)*cnt; } cnt*=q; } for(int i=2;i<=35;i++){ string pos=n; cnt=1; for(int j=0;j<pos.size();j++){ if(pos[i]<='9'){ h+=(pos[i]-'0')*cnt; }else{ h+=(pos[i]-87)*cnt; } cnt*=i; } if(h==t){ cout<<i; return 0; }else if(h>t){ break; } } } cout<<"NO"; return 0; }
任泓涛在2022-12-03 20:30:46追加了内容
任泓涛在2022-12-03 20:31:12追加了内容

#include <bits/stdc++.h>

using namespace std;

string n,m;

int p,q;

long long t,h;

string s="0123456789abcdefghijklmnopqrstuvwxyz";

int main(){

    cin>>n>>m>>p>>q;

    if(p==1){

        long long cnt=1;

        for(int i=0;i<n.size();i++){

            if(n[i]<='9'){

                t+=(n[i]-'0')*cnt;

            }else{

                t+=(n[i]-87)*cnt;

            }

            cnt*=q;

        }

        for(int i=2;i<=35;i++){

            string pos=m;

            h=0;

            cnt=1;

            for(int j=pos.size()-1;j>=0;j--){

                if(pos[j]<='9'){

                    h+=(pos[j]-'0')*cnt;

                }else{

                    h+=(pos[j]-87)*cnt;

                }   

                cnt*=i;

            }

            if(h==t){

                cout<<i;

                return 0;

            }else if(h>t){

                break;

            }

        }

    }else{

        long long cnt=1;

        for(int i=0;i<m.size();i++){

            if(m[i]<='9'){

                t+=(m[i]-'0')*cnt;

            }else{

                t+=(m[i]-87)*cnt;

            }

            cnt*=q;

        }

        for(int i=2;i<=35;i++){

            string pos=n;

            cnt=1;

            for(int j=0;j<pos.size();j++){

                if(pos[i]<='9'){

                    h+=(pos[i]-'0')*cnt;

                }else{

                    h+=(pos[i]-87)*cnt;

                }   

                cnt*=i;

            }

            if(h==t){

                cout<<i;

                return 0;

            }else if(h>t){

                break;

            }

        }

    }

    cout<<"NO";

    return 0;

}


0
已采纳
钱帅文
钱帅文
中级天翼
中级天翼

2个测试点也看不了啊

一个测试点我还能帮你看

0
任泓涛
任泓涛
资深守护
资深守护

已经解决了,我随机采纳

0
0
0
0
0
李乐天
李乐天
初级光能
初级光能

再见了,酷町堂,我要走了

0
我要回答