acm-2018-A-ICPC

Problem A : ICPC

The Iranian ChamPions Cup (ICPC), the most prestigious football league in Iran, is reaching its end, and people are eagerly waiting for the finals, which happened to be between the two most popular Iranian teams, Persepolis and Esteghlal.

The ICPC finals consist of two matches, with each team competing as the home team in one match. The winning team is determined by aggregate score, the sum of the scores of the two matches. For example, if the scores of the two matches are Persepolis 6–0 Esteghlal in the first match, and Esteghlal 3–1 Persepolis in the second match, then the aggregate score will be Persepolis 7–3 Esteghlal, meaning that Persepolis is the winner. If aggregates are equal, the away goals rule is used to determine the winner, in which case the winner is the team that scored the most goals in the match it played away from home. If the result is still equal, a penalty shootout is required.

Hana, an avid football fan, is trying to figure out various scenarios in which her favorite team wins the finals. To this
end, she aims to write a program that gets as input the number of goals in the two matches, and decides which team is the winner if it can be derived from the aggregate scores and the away goals rule, otherwise declares that the match goes to penalty kicks. You are going to help Hana write such a program.

Input

The first line of the input contains two space-separated integers p1 and s1, where p1 and s1 are the number of goals
scored by Persepolis and Esteghlal, respectively, in the first match in which Persepolis is the home team. The second
line contains two space-separated integers s2 and p2, where s2 and p2 are the number of goals scored by Esteghlal and Persepolis, respectively, in the second match in which Esteghlal is the home team. All input integers are between 0 and 20, inclusively.

Output

In the output, print the name of the winning team, either Persepolis or Esteghlal, if the winner can be determined
by the aggregate scores and the away goals rule. Otherwise, print Penalty.

Example


مساله الف) ICPC

لیگ برتر ایران، که معتبرترین لیگ در کشور است، در حال به پایان رسیدن است و مردم منتظر بازی پایانی هستن که بین دو تیم پرطرفدار پرسپولیس و استقلال برگزار خواهد شد.

فینال شامل 2 بازی می شود که هر بار یکی از تیم ها میزبان هست. تیم برنده بر اساس مجموع امتیاز ها مشخص می شود که در این دو بازی به دست آمده است. برای مثال، اگر نتایج برای دو بازی به صورت پرسپولیس 6-0 استقلال در بازی اول و استقلال 3-1 پرسپولیس در بازی دوم شود، در نتیجه مجموع نتایج برابر پرسپولیس 7-3 استقلال می شود، که یعنی پرسپولیس برنده می باشد. اگر مجموع نتایج با هم مساوی باشد، گل های زده شده باعث برنده شدن یک تیم می شود، و اگر این مورد هم یکی بود تعداد گل هایی که یک تیم خارج از خانه زده ملاک قرار می گیرد. اگر باز هم این نتیجه هم مساوی بود، به ضربات پنالتی کشیده می شود.

هانا ، یک هوادار مشتاق فوتبال ، در تلاش است تا سناریوهای مختلفی را که تیم محبوبش در فینال برنده می شود ، کشف کند. برای این منظور ، او قصد دارد برنامه ای بنویسد که تعداد گلهای دو مسابقه را به عنوان ورودی بگیرد، و تصمیم بگیرد از حاصل امتیازات و گل های زده کدام تیم برنده است یا به ضربات پنالتی کشیده می شود. شما هانا را کمک کنید که این برنامه را بنویسد.

ورودی

در خط اول شامل دو عدد با فاصله از هم p1 و s1 میباشد که p1 و s1 تعداد گلهای زده شده استقلال و پرسپولیس می باشد. همچنین همیشه پرسپولیس در بازی اول میزبان هست. در خط بعدی شامل دو عدد با فاصله از هم s2 و p2 میباشد که به ترتیب s2 و p2 تعداد گل های زده شده استقلال و پرسپولیس هست که استقلال میزبان بازی می باشد. تمام اعداد ورودی بین 0 تا 20 است.

خروجی

در خروجی، نام تیم برنده که یکی از تیم های پرسپولیس و استقلال هست را اگر بر اساس مجموع امتیاز ها و گل های زده شده مشخص می شود را چاپ کنید. در غیر اینصورت پنالتی را چاپ کنید.

مثال ها:

این تصویر دارای صفت خالی alt است؛ نام پروندهٔ آن image-3-1024x347.png است

راه حل – کد جاوا:

package acm2018.a;

import java.util.Arrays;
import java.util.List;

import util.AcmUtil;

public class ICPC {

	public static void main(String[] args) {
		List<String> fileContent = AcmUtil.readFromFile(path + "1.in");
		
		int p1,p2,s1,s2;
		
		int[] arr = processSpecifications(fileContent, 0);
		p1 = arr[0];
		s1 = arr[1];
		
		arr = processSpecifications(fileContent, 1);
		s2 = arr[0];
		p2 = arr[1];
		
		if (p1 + p2 > s1 + s2) {
			System.out.println("Persepolis");
		} else if (p1 + p2 < s1 + s2) {
			System.out.println("Esteghlal");
		} else if (p1 + p2 == s1 + s2) {
			if (p2 > s1)
				System.out.println("Persepolis");
			else if (p2 < s1)
				System.out.println("Esteghlal");
			else
				System.out.println("Penalty");
		}
		
		

		
	}
	
	public static int[] processSpecifications(List<String> fileContent, int index) {
		String[] arr  = fileContent.get(index).split(" ");
		return Arrays.stream(arr).mapToInt(Integer::parseInt).toArray();
	}

}

دیدگاهتان را بنویسید