Is the Name of This Problem: Difference between revisions
imported>Tlw37 |
imported>Tlw37 |
||
Line 1: | Line 1: | ||
==Problem== | ==Problem== | ||
http://speedyguy17.info/data/mcpc/mcpc2012/pdf/D-Is%20the%20Name%20of%20This%20Problem.pdf | |||
==Idea== | ==Idea== |
Revision as of 03:32, 5 December 2015
Problem
http://speedyguy17.info/data/mcpc/mcpc2012/pdf/D-Is%20the%20Name%20of%20This%20Problem.pdf
Idea
First, read in the next line and check to make sure that the first character is a quotation mark. We then continue to iterate through the String until we reach another quotation mark, and save the String that came between the quotes. We then check if the next character is an empty space. Finally, we save the rest of the String starting from the current index (1 after the blank space). We then check to make sure the two Strings are equal. If so, we print Quine(A), where A represents one of the equivalent Strings. If at any point in this process one of the conditions is not met, we immediately print "not a quine" and jump to processing the next line. Input is ended by a line containing the String "END".
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();
}
}