⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2142.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 2142 on 2006-02-25 at 22:54:26 */ 
#include <cstdio>
#include <cctype>
#include <cmath>

const int L_MAX = 256;
const int MAX = 32768;

class Inhabitant {
public:
	double pos;
	char name[L_MAX], dir;
	void make();
	double path(double) const;
};
void Inhabitant::make() {
	scanf("\n%c %lf %s", &dir, &pos, name);
	if(isupper(dir)) dir -= 'A'-'a';
}
double Inhabitant::path(double len) const {
	return (dir == 'p') ? len-pos : pos;
}

Inhabitant in[MAX];

int main()
{
	int i, n;

	while(scanf("%d", &n) != EOF && n != 0) {
		double l, v; scanf("%lf %lf", &l, &v);
		for(i = 0; i < n; i++) in[i].make();
		double last = 0; int lo;
		for(i = 0; i < n; i++) {
			double time = in[i].path(l) / v;
			if(last < time) last = time, lo = i;
		}
		int neg = 0;
		for(i = 0; i < n; i++)
			if(in[i].dir == in[lo].dir) continue;
			else if(in[lo].dir == 'p' && i > lo) neg++;
			else if(in[lo].dir == 'n' && i < lo) neg++;
		lo += (in[lo].dir == 'p') ? neg : -neg;
		printf("%13.2lf %s\n", floor(100*last)/100, in[lo].name);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -