当前位置:网站首页>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;
}
边栏推荐
- Canvas judgment content is empty
- @Classmethod decorator
- I2C can also be powered on by bus!
- Brush questions - Luogu -p1046 Tao Tao picking apples
- How happy is the frisbee bureau? 2022 youth trendy Sports Report
- Pytest.mark.parameterize and mock use
- hcip第八天实验
- sieve of eratosthenes
- Sword finger offer special assault edition day 10
- stable_ Baselines quick start
猜你喜欢

Leetcode1 -- sum of two numbers

【力扣】645.错误的集合
HTTP cache tongtianpian, there may be something you want

What is your revenue rank among global developers in 2022?
![Error of Tencent cloud [100007] this env is not enable anonymous login](/img/a2/a209a0d94e3fbf607242c28d87e2dd.png)
Error of Tencent cloud [100007] this env is not enable anonymous login

Discussion on principle and application technology of MLIR

Applet starts wechat payment

Introduction to jupyter notebook

IM system - some common problems of message streaming

刷题-洛谷-P1046 陶陶摘苹果
随机推荐
C # basic learning (XXIII)_ Forms and events
stable_ Baselines quick start
运动豪华还是安全豪华?亚洲龙与沃尔沃S60该入手哪款?
How happy is the frisbee bureau? 2022 youth trendy Sports Report
QGIS loading online map: Gaode, Tiandi map, etc
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
0715RHCSA
LabVIEW的内部错误
The migration of arm architecture to alsa lib and alsa utils is smooth
@Classmethod decorator
Serious [main] org.apache.catalina.util.lifecyclebase Handlesubclassexception initialization component
The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)
Canvas judgment content is empty
剑指offer专项突击版第10天
并发编程之并发工具集
电脑里一辈子都不想删的神仙软件
adb通过Wi-Fi连接小米手机
手写jdbc的使用步骤?
IM系统-消息流化一些常见问题
Uncaught SyntaxError: Octal literals are not allowed in strict mode.