Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String name, winner = "";
- int num, points = 0;
- while (!(name = scanner.nextLine()).equals("Stop")) {
- int currentPoints = 0;
- for (int i = 0; i < name.length(); i++) {
- num = Integer.parseInt(scanner.nextLine());
- int z = name.charAt(i);
- if (num == z) {
- currentPoints += 10;
- } else {
- currentPoints += 2;
- }
- }
- if (currentPoints >= points) {
- winner = name;
- points = currentPoints;
- }
- }
- System.out.println("The winner is " + winner + " with " + points + " points!");
- }
- }
- Решение с тернарен оператор и леко тарикатската:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String name, winner = "";
- int points = 0;
- while (!(name = scanner.nextLine()).equals("Stop")) {
- int currentPoints = 0;
- for (int i = 0; i < name.length(); i++) {
- currentPoints += Integer.parseInt(scanner.nextLine()) == name.charAt(i) ? 10 : 2;
- if (currentPoints >= points) {
- winner = name;
- points = currentPoints;
- }
- }
- }
- System.out.printf("The winner is %s with %d points!", winner, points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement