编程介的小学生 2017-02-11 16:27 采纳率: 20.5%
浏览 906
已采纳

Peter's smokes

Description
Peter has n cigarettes. He smokes them one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.
How many cigarettes can Peter have?
Input
Input is a sequence of lines. Each line contains two integer numbers giving the values of n and k.
Output
For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.
Sample Input
4 3
10 3
100 5
Sample Output
5
14
124

  • 写回答

1条回答 默认 最新

  • clam1234 2017-02-12 10:21
    关注

    我们可以这样理解题目的意思:
    Peter 有n根烟,他抽了k根后,又会得到一根烟,那么Peter一共可以抽多少根呢?给出的测试实例输入的是一开始有的烟,和K的大小,
    输出的是一共可以抽到的烟。那么这道题其实已经很简单了,下面是给出的C语言代码。
    #include
    using namespace std;
    int main()
    {
    int n,m;
    while( cin >> n >> m)
    {
    int k = n;
    while(n>m)
    {
    k = k + n/m;
    n = n%m + n/m;
    }
    cout << k << endl;
    }
    return 0;
    }
    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧