求解(87分)

P1480 A/B Problem

huangtianle666 @ 2024-11-02 10:29:07

#include<bits/stdc++.h>
using namespace std;
string n1,n2;
int a[5100],c[5200],la,lb,lc,x,w;
long long b;
int main(){
    cin>>n1;
    scanf("%lld",&b);
    la=n1.size();
    for(int i=1;i<=la;i++){
        a[i]=n1[la-i]-'0';
    }
    w=la+1;
    for(int i=w;i>=1;i--){
        c[i]=(x*10+a[i])/b;
        x=(x*10+a[i])%b;
    }
    lc=w+1;
    while(lc>1&&c[lc]==0){
        lc--;
    }
    for(int i=lc;i>=1;i--){
        printf("%d",c[i]);
    }
    return 0;
}

by zjhzjh412412 @ 2024-11-02 10:44:51

.........


by wky_wsy @ 2024-11-02 21:14:47

我不说python是自带高精的
所以代码可以短到酱:

a=int(input())
b=int(input())
print(a//b)

by Jhc123456a @ 2024-11-13 12:51:18

纯芝麻

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define int long long

const int P = 998244353;
const int INF = 0x3f3f3f3f3f3f3f3f;

const int N = 1e6 + 10, M = 2e6 + 10;

string sa;
int b;

int la, lc;
int a[N], c[N];

signed main()
{
cin >> sa >> b;
lc = la = sa.size();
for(int i=la-1; i>=0; i--)
{
a[la-i-1] = sa[i] - '0';
}
int r = 0;
for(int i=la-1; i>=0; i--)
{
r = r*10 + a[i];    //找到被除数
c[la-1-i] = r/b;    //存储商
r %= b;             //当前余数
}
reverse(c, c+lc);
while(lc && c[lc] == 0)
{
lc--;
}
for(int i=lc; i>=0; i--)
{
cout << c[i];
}
return 0;
}

|