Is the Name of This Problem

From programming_contest
Revision as of 03:16, 5 December 2015 by imported>Tlw37 (Created page with "==Introduction== The big media gimmick these days seems to be vampires. Vampire movies, vampire television shows, vampire books, vampire dolls, vampire cereal, vampire lipsti...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The big media gimmick these days seems to be vampires. Vampire movies, vampire television shows, vampire books, vampire dolls, vampire cereal, vampire lipstick, vampire bunnies – kids and teenagers and even some adults spend lots of time and money on vampire-related stuff. Surprisingly, nowadays vampires are often the good guys. Obviously, the ACM Programming Contest had better have a vampire problem in order to be considered culturally relevant. As eveyone knows, vampires are allergic to garlic, sunlight, crosses, wooden stakes, and the Internal Revenue Service. But curiously they spend a good part of their time smashing mirrors. Why? Well, mirrors can’t hurt vampires physically, but it’s embarrassing to be unable to cast a reflection. Mirrors hurt vampire’s feelings. This problem is about trying to help them avoid mirrors. In a room full of vampires and ordinary mortals there are a number of mirrors. Each mirror has one of four orientations – north, south, east, or west (the orientation indicates which side of the mirror reflects). A vampire is in danger of embarrassment if he or she is in a direct horizontal or vertical line with the reflecting side of a mirror, unless there are intervening objects (mortals or other mirrors). Your job is to notify each vampire of the directions in which there is danger of experiencing ENR (embarrassing non-reflectivity). link title Vampires


Idea

There are a few methods of solving this problem. The simplest way is to create a 2D grid where each point can be a wall, a vampire, a mortal, or a mirror. These 'points' can either be their own objects or can be mapped to a single integer. Then, we simply iterate through every vampire and go in each cardinal direction and see if any mirrors reflect back to it (ignoring all the irrelevant objects).

Code

Solution - Java

package accepted;
import java.util.Scanner;

public class Problem_AL_Is_the_Name_of_This_Problem {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		while (true) {
			String input = scan.nextLine();
			String inQuotes = "", outOfQuotes = "";
			int index = 0;

			if (input.equals("END"))
				break;

			if (input.charAt(index++) != '"') {
				System.out.println("not a quine");
				continue;
			}

			boolean endOfString = false;
			while (true) {
				if (index + 1 >= input.length()) {
					endOfString = true;
					break;
				}

				char c = input.charAt(index++);
				if (c == '"') {
					break;
				}

				inQuotes += c;
			}

			if (endOfString || input.charAt(index) != ' ') {
				System.out.println("not a quine");
				continue;
			}

			if (index + 1 < input.length()) {
				outOfQuotes = input.substring(++index);
			}

			if (inQuotes.equals(outOfQuotes)) {
				System.out.println("Quine(" + inQuotes + ")");
			} else {
				System.out.println("not a quine");
			}
		}
		scan.close();
	}
}