1865 - 奋斗的小蜗牛

通过次数

0

提交次数

0

时间限制 : 3 秒 内存限制 : 128 MB

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

题目输入

第一行有一个整数t,表示t组测试数据。
第二行一个整数H(0<H<10^9)代表金字塔的高度。

题目输出

输出一个整数n表示小蜗牛第n天站在金字塔顶上

输入/输出样例

输入格式

2
1
5

输出格式

1
1

C语言解答

#include<stdio.h>
int main()
{
	int t,H;
	scanf("%d",&t);
	while(t--)
	{
		int n=0;
		scanf("%d",&H);
		do
		{
			H-=10;
			if(H>0)
				H+=5;
			n++;
		}while(H>0);
		printf("%d\n",n);
	}
}

Java解答

import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for(int i=1;i<=t;i++){
			int H=sc.nextInt();
			int m=H%10;
			if(H<=10){
				System.out.println(1);
			}else if(H%5==0){
				System.out.println(H/5-1);
			}else{
				System.out.println(H/5);
			}
		}
	}
}