-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqishui.c
50 lines (45 loc) · 927 Bytes
/
qishui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <windows.h>
#pragma warning(disable:4996)
int main()
{
int money = 0;
scanf("%d",&money);
printf("%d\n",2*money - 1);
system("pause");
return 0;
}
//分析
//首先喝完用空瓶换,完了再用空瓶换到最最后不能换的时候,手中肯定只剩一个一个空瓶
//假如有N块钱,则喝完有N个空瓶,问老板借N-1个空瓶,则可再换N-1瓶汽水,
//完了之后把喝完的N-1个空瓶还给老板,则刚好喝了2N-1瓶汽水,而且手中余一个空瓶
//
//int count_bottle_num(int money)
//{
// int num = 0;
// int null_bottle = 0;
// int full_bottle = money;
// while (1)
// {
// num += full_bottle;
// null_bottle = full_bottle+null_bottle%2;
// full_bottle = null_bottle / 2;
// if (null_bottle == 1)
// {
// return num+1;
//
// }
// }
//
//}
//int main()
//{
// int money = 0;
// printf("请输入金额:");
// scanf("%d",&money);
// printf("%d元钱可以喝%d瓶汽水!!\n",money,count_bottle_num(money));
//
//
// system("pause");
// return 0;
//}