空瓶换啤酒-----if判断和while循环易错

Soda Surpler

Description
Tim is an absolutely obsessive soda drinker,he simply cannot get enough. Most annoyingly
though, he almost never has any money, so his only obvious legal way to obtain more soda is to take the money he gets when he recycles empty soda bottles to buy new ones. In addition to the empty bottles resulting from his own consumption he sometimes find empty bottles in the street. One day he was extra thirsty, so he actually drank sodas until he couldn’t aford a new one.

Input
Three non-negative integers e,f, c, where e < 1000 equals the number of empty soda
bottles in Tim’s possession at the start of the day, f < 1000 the number of empty soda
bottles found during the day, and 1 < c < 2000 the number of empty bottles required to
buy a new soda.
Output
How many sodas did Tim drink on his extra thirsty day?

Sample Input
9 0 3
5 5 2
Sample Output
4
9

#include<stdio.h>
#include<string.h>
int main(){
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c)!=EOF){
		int count=0;
		a=a+b;
		while(a>=c){
			count+=a/c;
			a=a/c+a%c;
		}
		printf("%d\n",count);
	}
//	for(int j=0;j<n;j++)
//	printf("%d\n",s[j]);
	return 0;
}

依然是华丽丽的分割线~这个题目最深的印象是要进入第一层while循环之后,第二层循环一开始用的If判断语句,结果每次都不对,后来改了几次才发现最重要的是把if换成while这样才能在满足剩余的啤酒瓶数量大于换酒所需要的空瓶的数量。
简单C语言中容易出错的地方,更需要注意!!!
永远学习,
永远在路上。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值