奋斗的小蜗牛

描述传说中能站在金字塔顶的只有两种动物,一种是鹰,一种是蜗牛。一只小蜗牛听了这个传说后,大受鼓舞,立志要爬上金字塔。为了实现自己的梦想,蜗牛找到了老鹰,老鹰告诉它金字塔高H米,小蜗牛知道一个白天自己能向上爬10米,但由于晚上要休息,自己会下滑5米。它想知道自己在第几天能站在金字塔顶,它想让你帮他写个程序帮助它。

 
输入
第一行有一个整数t,表示t组测试数据。
第二行一个整数H(0<H<10^9)代表金字塔的高度。
输出
输出一个整数n表示小蜗牛第n天站在金字塔顶上
样例输入
2
1
5
样例输出
1
1

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner scanner=new Scanner(System.in);
 6         int T;
 7         int n;
 8         int count;
 9         
10         T=scanner.nextInt();
11         while(true){
12             if(T==0)
13                 break;
14             T--;
15             
16             n=scanner.nextInt();
17             count=0;
18             while(true){
19                 if(n<=10){
20                     count++;
21                     break;
22                 }
23                 else{
24                     n-=5;
25                     count++;
26                 }
27             }
28             System.out.println(count);
29         }     
30     } 
31 }

 

 
posted @ 2014-11-30 15:51  zqxLonely  阅读(303)  评论(0编辑  收藏  举报