愤怒小鸟

X星球愤怒的小鸟喜欢撞火车!

一根平直的铁轨上两火车间相距 1000 米。

两火车 (不妨称A和B) 以时速 10米/秒 相对行驶。

愤怒的小鸟从A车出发,时速50米/秒,撞向B车,然后返回去撞A车,再返回去撞B车,如此往复....

两火车在相距1米处停车。

问:这期间愤怒的小鸟撞 B 车多少次?

注意:需要提交的是一个整数(表示撞B车的次数),不要填写任何其它内容。

答案:(48分)

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    double x = 1000;
    int c = 0;
    while(x > 1) {
        double ti = x / 60;
        x -= ti * 20;
        if(x <= 1) break;
        c ++;
        ti = x / 60;
        x -= ti * 20;
    }
    cout<<c<<endl;
}
public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        double x = 1000;
        int c = 0;
        while(x > 1) {
            double ti = x / 60;
            x -= ti * 20;
            if(x <= 1) break;
            c ++;
            ti = x / 60;
            x -= ti * 20;
        }
        System.out.println(c);
    }
}
原文地址:https://www.cnblogs.com/8023spz/p/10546013.html