求助!总是卡最后一个样例,样例输入为9000000000和1000000000

P1480 A/B Problem

Vivian2022 @ 2024-09-11 17:44:15

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> div(vector<int>&A,int b,int&r)
{ vector<int>C;
 r=0;
 for(int i=A.size()-1;i>=0;i--)
 {  r=r*10+A[i];
 C.push_back(r/b);
 r%=b;
 }
 reverse(C.begin(),C.end());
 while(C.size()>1&&C.back()==0) C.pop_back();
 return C;
}
int main()
{string a;
long long b;
cin>>a>>b;
vector<int>A;
for(int i=a.size()-1;i>=0;i--) A.push_back(a[i]-'0');
int r;
vector<int> C=div(A,b,r);
for(int i=C.size()-1;i>=0;i--)
printf("%d",C[i]);

}

by Zhetengtiao @ 2024-09-11 18:00:15

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> div(vector<int>&A,long long b,long long&r)
{
    vector<int>C;
    r=0;
    for(int i=A.size()-1;i>=0;i--)
    {   
        r=r*10+A[i];
        C.push_back(r/b);
        r%=b;
    }
    reverse(C.begin(),C.end());
    while(C.size()>1&&C.back()==0) C.pop_back();
    return C;
}
int main()
{
    string a;
    long long b;
    cin>>a>>b;
    vector<int>A;
    for(int i=a.size()-1;i>=0;i--) A.push_back(a[i]-'0');
    long long r;
    vector<int> C=div(A,b,r);
    for(int i=C.size()-1;i>=0;i--)
    printf("%d",C[i]);
}

->

vector<int> div(vector<int>&A,long long b,long long&r)
    long long r;

by Simonyu2013 @ 2024-10-22 10:51:37

开 long long


|