当前位置:网站首页>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 .
}
边栏推荐
- 洛谷P4047 [JSOI2010]部落划分 题解
- tonybot 人形機器人 紅外遙控玩法 0630
- 剑指 Offer 28. 对称的二叉树
- Exercise 8-8 moving letters
- String sort
- 7-24 reduction of the simplest fraction (rolling Division)
- Zabbix添加Calculated items后保存页面成空白
- Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
- Output student grades
- Convert string to decimal integer
猜你喜欢

分布式事务(Seata) 四大模式详解

分布式事务(Seata) 四大模式详解
![Luogu p4047 [jsoi2010] tribal division solution](/img/7f/3fab3e94abef3da1f5652db35361df.png)
Luogu p4047 [jsoi2010] tribal division solution

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue

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

Programming language: the essence of type system

Detailed explanation of four modes of distributed transaction (Seata)

泰凌冲刺科创板:拟募资13亿 国家大基金与小米长江是股东

天谋科技 Timecho 完成近亿元人民币天使轮融资,打造工业物联网原生时序数据库

X86 assembly language - Notes from real mode to protected mode
随机推荐
洛谷P3065 [USACO12DEC]First! G 题解
SSH访问控制,多次失败登录即封掉IP,防止暴力破解
Mongodb index
Output student grades
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
NPM install is stuck with various strange errors of node NPY
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
How Facebook moves instagram from AWS to its own server
Detailed explanation of four modes of distributed transaction (Seata)
556. 下一个更大元素 III
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
Table of mathematical constants by q779
Analysis of gene family characteristics - chromosome location analysis
7-24 reduction of the simplest fraction (rolling Division)
ZABBIX saves the page blank after adding calculated items
fpga阻塞赋值和非阻塞赋值
MongoDB索引
Bibit pharmaceutical rushed to the scientific innovation board: annual revenue of 970000, loss of 137million, proposed to raise 2billion
C language,%d% Difference between 2D%2d%02d
556. 下一个更大元素 III : 简单构造模拟题