当前位置:网站首页>Pat class B 1017 C language
Pat class B 1017 C language
2022-06-23 05:57:00 【Octopus bro】
1017. A Divide B (20)
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 :
Enter in 1 In turn, we give A and B, In the middle to 1 The blank space to separate .
Output format :
stay 1 Output in turn Q and R, In the middle to 1 The blank space to separate .
sample input :123456789050987654321 7sample output :
17636684150141093474 3
Ideas : You can only convert a string bit by bit into a number . The dividend is converted from the left side of the string to a digit divided by the divisor , If there is a remainder multiplied by 10 Save for the next , Otherwise zero , Remainder multiplication 10 Save for the next . Note that if the first divisor is less than the divisor, zero cannot be output , Only when there is a non-zero output can it be output 0
One 、 Starting variable
1. Divisor divider, Divisor dibideder, Each remainder left
2.flag Sign a , Non zero output used to mark whether there is quotient
Two 、 operation
1. Read the dividend and divisor .
2. stay for In the loop, the divisor is converted bit by bit , Convert one digit divided by the divisor , If not zero output , If zero , Output on the premise that there is already a non-zero quotient output , Otherwise, it will not output .
3. If there is a remainder multiplied by 10 Save for the next
4. if flag Always for 0, Then the dividend is less than the divisor , Output 0
3、 ... and 、 Code
#include "stdio.h"
#include "string.h"
int main()
{
char divideder[1001];
int divider;
int flag = 0;// Whether there is a non-zero quotient output , Before there is no non-zero output 0 No output ;
int i;
int left = 0;// The remainder after each division ;
scanf("%s %d", divideder, ÷r);
int len = strlen(divideder);
// If the divisor is 0, Direct results ;
for(i = 0; i < len; i++)
{
left = left*10 + divideder[i] - '0';
if(left >= divider)
{
printf("%d",left / divider);
flag = 1;// export merchant , And change flag Value ,flag Is a flag indicating whether a quotient of a bit is output
}
else if(flag)
{
printf("0");// After the first output of the quotient , And the third of the divisor i Bit less than divisor , The output 0;
}
left = left % divider;// Get the remainder
}
if(flag == 0)
{
printf("0");
}// The divisor has only one digit and is less than the divisor ;
printf(" %d",left);
return 0;
}边栏推荐
- Leetcode topic resolution divide two integers
- Pat class B 1010 C language
- Wechat applet: elderly blessing short video
- JS面试题----防抖函数
- True MySQL interview question (XXII) -- condition screening and grouping screening after table connection
- PAT 乙等 1020.月饼
- jvm-06. Garbage collector
- Centos7 deploy radius service -freeradius-3.0.13-15 EL7 integrating MySQL
- jvm-02. Guarantee of orderliness
- Leetcode topic analysis: factorial training zeroes
猜你喜欢

jvm-03.jvm内存模型

True MySQL interview question (24) -- row column exchange

Prometheus, incluxdb2.2 installation and flume_ Export download compile use

MySQL面试真题(二十一)——金融-贷款逾期

Wechat applet; AI intelligent dubbing assistant
![[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code](/img/e2/24eb2a60e3dc603b3ec4bfefd0b8e5.png)
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code

Redis cache penetration solution - bloom filter

Arctime makes Chinese and English subtitle video

Genetic engineering of AI art? Use # artbreeder to change any shape of the image

C primer plus學習筆記 —— 2、常量與格式化IO(輸入/輸出)
随机推荐
制造业数字化转型存在问题及原因分析
MDM data cleaning function development description
工作积累-判断GPS是否打开
MySQL面试真题(二十四)——行列互换
APP SHA1获取程序 百度地图 高德地图获取SHA1值的简单程序
Pat class B 1009 C language
Work accumulation - judge whether GPS is on
MySQL面试真题(二十八)——案例-通讯运营商指标分析
Centos7 deploy radius service -freeradius-3.0.13-15 EL7 integrating MySQL
Kotlin Android simple activity jump, simple combination of handler and thread
Prometheus, incluxdb2.2 installation and flume_ Export download compile use
The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming
Addressing and addressing units
Pat class B 1012 C language
The difference between SaaS software and traditional software delivery mode
Explanation of penetration test process and methodology (Introduction to web security 04)
jvm-06. Garbage collector
jvm-04.对象的内存布局
数字藏品到底有什么魔力?目前有哪些靠谱的团队在开发
数字藏品——新的投资机遇