A除以B (20) (模拟除法)
生活随笔
收集整理的這篇文章主要介紹了
A除以B (20) (模拟除法)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目描述
本題要求計算A/B,其中A是不超過1000位的正整數,B是1位正整數。你需要輸出商數Q和余數R,使得A = B * Q + R成立。?
輸入描述:
輸入在1行中依次給出A和B,中間以1空格分隔。
?
輸出描述:
在1行中依次輸出Q和R,中間以1空格分隔。?
輸入例子:
123456789050987654321 7?
輸出例子:
17636684150141093474 3?
?
此題為一道純模擬題,模擬除法,感覺特別經典。。。。。。
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<string>using namespace std;const int maxn = 1100; char s[maxn];int main() {int n;scanf("%s%d", s, &n);int t = strlen(s);if(t == 1){int now = (s[0] - '0') / n;int temp = (s[0] - '0') % n;printf("%d %d\n", now, temp);}else{int now, temp = s[0] - '0';for(int i = 1; i < t; i++){now = temp*10 + (s[i] - '0');printf("%d", now / n);temp = now % n;}printf(" %d\n", temp);}return 0; }?
總結
以上是生活随笔為你收集整理的A除以B (20) (模拟除法)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cities (思维 树)
- 下一篇: 部分和问题 (dfs搜索 尺取)