2142.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 49 行

CPP
49
字号
/*  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 + =
减小字号Ctrl + -
显示快捷键?