当前位置:网站首页>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 3Ideas : 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 .
}
边栏推荐
猜你喜欢

ShowMeBug入驻腾讯会议,开启专业级技术面试时代

Niuke: crossing the river

Tonybot humanoid robot checks the port and corresponds to port 0701

NPM install is stuck with various strange errors of node NPY

Understanding of closures
![[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?](/img/f6/fe61c84f289f0e74a45946dac687a6.jpg)
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
![Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution](/img/89/da1a3a38e02671628f385de0f30369.png)
Luogu p5018 [noip2018 popularization group] symmetric binary tree problem solution

Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Tonybot humanoid robot starts for the first time 0630
随机推荐
分布式事务(Seata) 四大模式详解
Luogu p5194 [usaco05dec]scales s solution
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
fpga阻塞赋值和非阻塞赋值
How Facebook moves instagram from AWS to its own server
基因家族特征分析 - 染色体定位分析
7-28 monkeys choose King (Joseph problem)
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
7-14 sum integer segments (C language)
Detailed explanation of four modes of distributed transaction (Seata)
Doris学习笔记之数据表的创建
修改数据库中的记录为什么报这个错
数学常数表 by q779
tonybot 人形機器人 紅外遙控玩法 0630
Puzzle (016.4) domino effect
tonybot 人形机器人 首次开机 0630
npm install卡住与node-npy的各种奇怪报错
动态获取权限
超简单手机地图开发
全文检索引擎Solr系列—–全文检索基本原理