当前位置:网站首页>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 .
}
边栏推荐
- LNMP环境mail函数不能发送邮件解决
- Timecho of Tianmou technology completed an angel round financing of nearly 100 million yuan to create a native timing database of the industrial Internet of things
- Puzzle (016.4) domino effect
- Common shortcut keys in PCB
- Niuke: crossing the river
- etcd集群权限管理和账号密码使用
- Sub-GHz无线解决方案Z-Wave 800 系列ZG23 soc和ZGM230S模块
- Raft agreement
- Sub GHz wireless solution Z-Wave 800 Series zg23 SOC and zgm230s modules
- ShowMeBug入驻腾讯会议,开启专业级技术面试时代
猜你喜欢

基因家族特征分析 - 染色体定位分析

x86汇编语言-从实模式到保护模式 笔记

Code writing and playing method of tonybot humanoid robot at fixed distance

使用并行可微模拟加速策略学习

亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

NPM install is stuck with various strange errors of node NPY

Puzzle (016.3) is inextricably linked

Understand the application scenario and implementation mechanism of differential segment

Leetcode (4) -- find the median of two positively ordered arrays
随机推荐
洛谷P4047 [JSOI2010]部落划分 题解
MongoDB数据库入门的常用命令
7-16 find the set of integers that meet the given conditions
适用于XP的DDK
MySQL multi table query subquery
表单文本框的使用(一) 选择文本
Puzzle (016.4) domino effect
Adc128s022 ADC Verilog design and Implementation
tonybot 人形机器人 红外遥控玩法 0630
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
Although not necessarily the best, it must be the hardest!
Code writing and playing method of tonybot humanoid robot at fixed distance
Analysis of gene family characteristics - chromosome location analysis
Doris学习笔记之数据表的创建
Programming language: the essence of type system
etcd集群权限管理和账号密码使用
7-4 BCD decryption (10 points)
Facebook 如何将 Instagram 从 AWS 搬到自己的服务器
基因家族特征分析 - 染色体定位分析
7-6 mixed type data format input