排队喝饮料

问题:B - 2 CodeForces - 82A
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a “Double Cola” drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.

For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.

Write a program that will print the name of a man who will drink the n-th can.

Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.

Input
The input data consist of a single integer n (1 ≤ n ≤ 109).

It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.

Output
Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: “Sheldon”, “Leonard”, “Penny”, “Rajesh”, “Howard” (without the quotes). In that order precisely the friends are in the queue initially.

Examples
Input
1
Output
Sheldon
Input
6
Output
Sheldon
Input
1802
Output
Penny
问题链接
问题大意:五个人排队喝水;喝完之后就到最后去,一个就变成两个一样的人;然后输入一个数字,判断是谁喝了这杯水;
代码如下(已AC):

#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int m = 1;
	for (; n - 5 * m > 0; )
	{
		n = n - 5 * m;
		m = 2 * m;
	}//如果n<=0,就说明轮完了,m代表一个人分成了几个人;
	if(n<=m)
		cout << "Sheldon";
	else if(n<=2*m)
	    cout << "Leonard";
	else if(n<=3*m)
	     cout << "Penny";
	else if(n<=4*m)
	    cout << "Rajesh";
	else
	  cout << "Howard";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44002750/article/details/86621555