当前位置:网站首页>1017 a divided by B (20 points)
1017 a divided by B (20 points)
2022-07-03 14:33:00 【Study hard 867】
This problem requires calculation A/B, among A No more than 1000 Bit positive integer ,B yes 1 Positive integer . You need to export quotient Q And the remainder R, bring A=B×Q+R establish .
Input format :
The input is given in turn on a line A and B, In the middle to 1 The blank space to separate .
Output format :
Output sequentially in a row Q and R, In the middle to 1 The blank space to separate .
sample input :
123456789050987654321 7
sample output :
17636684150141093474 3
Ideas : Any method in the computer is the most advanced method that people think, so we only need to think of the method we think of , If we were to find the divisor and remainder , We will use the division operation we have learned to do , First, let's see if the first digit is less than the divisor , If it's less than , Let's go back , Because there is no number in front , So we can't mark 0, That is to say, the first one is special , Because we are not used to 1456 Make it 01456 In the form of , So the first is special , We need to mark , Then if our current remainder is less than the divisor , We should output 0, No. , We will % operation , So you can get the next time % Value . Special attention should be paid here to the case that the divisor is less than the dividend .
Code :
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1001];
int number;
scanf("%s%d",a,&number);
int i,tool=0;//tool I mean the remainder
char b[1001];// Used to record divisors, that is, quotients
int size=0;
memset(b,0,sizeof(b));
int alen=strlen(a);
for(i=0; i<alen; i++) {
tool=tool*10+a[i]-'0';
if(i==0&&tool<number)continue;// The first special treatment .
else if(tool<number){// Less than 0 Just throw it in 0
b[size++]='0';
}
else if(tool>=number){// If greater than, take the remainder , And put the business into b Array
b[size++]=(char)((tool)/number+'0');
tool=tool%number;
}
}
if(b[0]!='\0')printf("%s %d",b,tool);
else printf("0 %d",tool,tool);// If the value is less than the divisor, then the divisor is 0, The remainder is the divisor .
}
边栏推荐
- Understand the application scenario and implementation mechanism of differential segment
- tonybot 人形机器人 首次开机 0630
- 洛谷P3065 [USACO12DEC]First! G 题解
- Etcd cluster permission management and account password usage
- Ultra simple mobile map development
- Table of mathematical constants by q779
- MySQL multi table query subquery
- 【7.3】146. LRU缓存机制
- 剑指 Offer 28. 对称的二叉树
- Eight sorts
猜你喜欢
修改数据库中的记录为什么报这个错
Exercise 8-8 moving letters
天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库
tonybot 人形机器人 定距移动 代码编写玩法
ConstraintLayout 的使用
Adc128s022 ADC Verilog design and Implementation
Code writing and playing method of tonybot humanoid robot at fixed distance
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Leetcode(4)——尋找兩個正序數組的中比特數
tonybot 人形机器人 查看端口并对应端口 0701
随机推荐
NPM install is stuck with various strange errors of node NPY
洛谷P5194 [USACO05DEC]Scales S 题解
Pyqt interface production (login + jump page)
556. The next larger element III
Too many files with unapproved license
String sort
Find specified characters
7-24 reduction of the simplest fraction (rolling Division)
adc128s022 ADC verilog设计实现
Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
Tonybot humanoid robot infrared remote control play 0630
Exercise 6-6 use a function to output an integer in reverse order
表单文本框的使用(一) 选择文本
How to query the baby category of tmall on Taobao
Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
Showmebug entered Tencent conference, opening the era of professional technical interview
【7.3】146. LRU缓存机制
Niuke: crossing the river
使用并行可微模拟加速策略学习
Common shortcut keys in PCB