NOI1 13 47 大整數除法 題解 C

2021-10-04 23:49:42 字數 1413 閱讀 9111

這題一看題目就知道絕非普通的long long 或 int 。這可是高精度呀。

47:大整數除法

總time limit: 1000ms memory limit: 65536kb

description

求兩個大的正整數相除的商。

input

第1行是被除數,第2行是除數。每個數均不超過100位。//刺激不??

output

一行,相應的商的整數部分

sample input

2376

24sample output

99先給大家看乙個豎式(重回3年級)

可以看出

大家千萬不要被樣例資料給騙了,不然怎麼會出現在1.13捏,這可是可以毀滅long long 的數字啊必須使用高精度了,我也沒辦法。。。

我們要考慮以下兩點:

題目可沒有說除數一定不為0哦,要預判(8分9分看過來)。出題人還真是態度惡劣啊

根據除法算式可以得知

·a. 大整數乘整數(int)了解一下~

·b. 大整數減法了解一下~

#include

using

namespace std;

#define tail head+len2-1

//與head聯動的tail 記錄除數的尾部指標

const

int maxn=

10001

;int len1,len2,cur=1;

char s1[maxn]

,s2[maxn]

;int a[maxn]

,b[maxn]

,c[maxn]

,ans[maxn]

;bool

compare

(int head)

if(str1>=str2)

return1;

//使用過載過的string模擬較

else

return0;

//如果大於等於就減 小於則不能減

}int

sub(

int head)

} ans[tail]++;

//統計答案

}int

main()

cur=1;

while

( ans[cur]==0

&& cur!=len1 )cur++

;//去除前面的0

for(

int i=cur;i<=len1;i++

)printf

("%d"

,ans[i]);

//輸出

}

大整數除法

define maxint 1000 define max 200 int num1 max 10 int num2 max 10 unsigned int total max 10 int sub int a,int b int i 0 for a b i return i cstring big...

高精度正整數除法 大整數除法

標籤 空格分隔 演算法競賽 演算法 程式設計錯題 高精度 單詞 divident 被除數 divisor 除數 quotient 商大整數除法 openj bailian 2737 題目要求 求兩個大的正整數相除的商。input 第1行是被除數,第2行是除數。每個數均不超過100位。output 一...

高精度正整數除法 大整數除法

標籤 空格分隔 演算法競賽 演算法 程式設計錯題 高精度 單詞 divident 被除數 divisor 除數 quotient 商大整數除法 openj bailian 2737 題目要求 求兩個大的正整數相除的商。input 第1行是被除數,第2行是除數。每個數均不超過100位。output 一...