Практикум по программированию. Основы. Обработка строк. Победитель конкурса

From AsIsWiki
Jump to: navigation, search

Назад · Задачи · Дальше


Contents

Java

import java.util.Scanner;

public class Task04 {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in, "CP1251");

        System.out.println();
        System.out.println(" Поиск победителя конкурса ");
        System.out.println("---------------------------");

        System.out.print(" Количество участников: ");
        int n = in.nextInt();

        System.out.println("---------------------------");

        String lastnames[] = new String[n];
        int scores[] = new int[n];

        for (int i = 0; i < n; i++) {

            System.out.printf(" %d Фамилия: ", i + 1);

            lastnames[i] = in.next();

            System.out.print("     Баллы: ");

            scores[i] = in.nextInt();
        }

	int max = 0, num = 0;

	for (int i = 0; i < n; i++) {
	    if (max < scores[i]) {
		max = scores[i];
		num = i;
	    }
	}

        System.out.println("---------------------------");

	String sf = "баллов";

	if ((max % 10 > 1) && (max % 10 < 5) && ((max % 100 < 12) || (max % 100 > 14))) {
	    sf = "балла";
	} else {
	    if ((max % 10 == 1) && (max % 100 != 11)) {
		sf = "балл"; 
	    }
	}

	System.out.printf(" Победил: %s, набрав %d %s\n", lastnames[num], max, sf);
    }
}


C++



Pascal




Назад · Задачи · Дальше

Personal tools
Namespaces

Variants
Actions
Navigation
Tools