当前位置:网站首页>Brush questions - Luogu -p1150 Peter's smoke
Brush questions - Luogu -p1150 Peter's smoke
2022-07-25 13:46:00 【Song Xiangshang_ UP】
P1150 Peter The smoke of -C Language
1、 subject

2、 The problem solving process
(1) for the first time while Insufficient conditions in the loop , Should be surplus >=k
result :
Code :
// Luogu P1150 Peter The smoke of
#include <stdio.h>
int main() {
int n;//Peter The original number of cigarettes
int k;//k(k>1) A cigarette butt can be exchanged for a new cigarette
int sum=0;//Peter The number of cigarettes you can smoke
int exchange;// The number that can be exchanged
int surplus;// The number of cigarettes remaining that have not been exchanged
//int i = 1;
scanf_s("%d %d", &n, &k);
sum = n;// Original smoke number
exchange = n / k;// The number of cigarettes that can be exchanged
sum = sum + exchange;
surplus = n - exchange * k+ exchange;// Number of cigarettes remaining
while (surplus > k) {
exchange = surplus / k;// Number of cigarettes exchanged
sum = sum + exchange;
surplus = surplus - exchange * k + exchange;
//printf(" Implemented section %d Time \n", i);
//i++;
}
printf("%d", sum);
return 0;
}
(2) The second time
result :
Code :
// Luogu P1150 Peter The smoke of
#include <stdio.h>
int main() {
int n;//Peter The original number of cigarettes
int k;//k(k>1) A cigarette butt can be exchanged for a new cigarette
int sum=0;//Peter The number of cigarettes you can smoke
int exchange;// The number that can be exchanged
int surplus;// The number of cigarettes remaining that have not been exchanged
//int i = 1;
scanf("%d %d", &n, &k);
sum = n;// Original smoke number
exchange = n / k;// The number of cigarettes that can be exchanged
sum = sum + exchange;
surplus = n - exchange * k+ exchange;// Number of cigarettes remaining
while (surplus >= k) {
exchange = surplus / k;// Number of cigarettes exchanged
sum = sum + exchange;
surplus = surplus - exchange * k + exchange;
//printf(" Implemented section %d Time \n", i);
//i++;
}
printf("%d", sum);
return 0;
}
边栏推荐
- Internal error of LabVIEW
- pycharm不能输入中文解决方法
- "Digital security" alert NFT's seven Scams
- Peripheral system calls SAP's webapi interface
- Arrays常用方法
- 互斥锁、自旋锁、读写锁……理清它们的区别和应用
- 并发编程之阻塞队列
- 0717RHCSA
- What should I do if the high-level MySQL server cannot be installed and I forget the password (MySQL 8.0.29)?
- Mxnet implementation of densenet (dense connection network)
猜你喜欢

【力扣】1030.距离顺序排列矩阵单元格

运动豪华还是安全豪华?亚洲龙与沃尔沃S60该入手哪款?

Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式

Basic knowledge of binary tree

Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?

Introduction to jupyter notebook

2022全球开发者中,你的收入排多少?

Brush questions - Luogu -p1046 Tao Tao picking apples

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
Congestion control of TCP
随机推荐
NoSQL,关系型数据库,行列数据库对比、类比
Peripheral system calls SAP's webapi interface
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
uniapp处理后台传输图片
刷题-洛谷-P1161 开灯
leetcode1 --两数之和
sieve of eratosthenes
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
ADB connects to Xiaomi mobile phone via Wi Fi
职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?
【配置Hifive1-revB】设备管理器中不识别端口,Can not connect to J-Link via USB的解决办法
HTTP cache tongtianpian, there may be something you want
Prepare for 2022 csp-j1 2022 csp-s1 preliminaries video set
The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)
hcip第七天笔记
说说对hashcode和equals方法的理解?
hcip第十天笔记
Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
Discussion on principle and application technology of MLIR
Applet enterprise red envelope function