0
点赞
收藏
分享

微信扫一扫

青蛙爬井


青蛙爬井


Time Limit: 1 Sec Memory Limit: 128 MB

Submit: 2079

Solved: 1423


Submit

Status

Web Board


Description


有一口深度为high米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬up米,夜里则顺井壁向下滑down米,若青蛙从某个早晨开始向外爬,对于任意指定的high、up和down值(均为自然数),计算青蛙多少天能够爬出井口?


Input


输入3个正整数:high、up和down。


Output


输出一个整数,表示天数。输出单独占一行。


Sample Input


10 2 1


Sample Output


9

源代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int high,up,down,day,t;
  scanf("%d%d%d",&high,&up,&down);
  day=0,t=0;
  while(t<=high)
  {
    t=t+up;
    day++;
    if(t>=high)
      break;
    else
      t=t-down;             
  }
  printf("%d\n",day);
  system("pause");
  return 0;    
}

举报

相关推荐

0 条评论