2014
03-23

# Universal Oracle

In computer science, an oracle is something that gives you the answer to a particular question. For this problem, you need to write an oracle that gives the answer to everything. But it’s not as bad as it sounds; you know that 42 is the answer to life, the universe, and everything.

The input consists of a single line of text with at most 1000 characters. This text will contain only well-formed English sentences. The only characters that will be found in the text are uppercase and lowercase letters, spaces, hyphens, apostrophes, commas, semicolons, periods, and question marks. Furthermore, each sentence begins with a single uppercase letter and ends with either a period or a question mark. Besides these locations, no other uppercase letters, periods, or question marks will appear in the sentence. Finally, every question (that is, a sentence that ends with a question mark) will begin with the phrase “What is…”

The input consists of a single line of text with at most 1000 characters. This text will contain only well-formed English sentences. The only characters that will be found in the text are uppercase and lowercase letters, spaces, hyphens, apostrophes, commas, semicolons, periods, and question marks. Furthermore, each sentence begins with a single uppercase letter and ends with either a period or a question mark. Besides these locations, no other uppercase letters, periods, or question marks will appear in the sentence. Finally, every question (that is, a sentence that ends with a question mark) will begin with the phrase “What is…”

Let me ask you two questions. What is the answer to life? What is the answer to the universe?

Forty-two is the answer to life.
Forty-two is the answer to the universe.

/*
这是昨天比赛很水的题目，而我却没有做出来，真是不应该的；
题目没有看仔细，What 以.结尾不要 回答的，这点注意就OK
发现STL很强大，决定好好学下。
*/
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main()
{
string str;
while( getline(cin, str) )
{
string str1 = "What";
size_t found1;
found1 = str.find(str1);
int i;
while(found1 != string::npos)
{
int len = str.size();
for(i = found1 + 4; i < len; i++)
{
if(str[i] == '?')
{
cout << "Forty-two";
for(int j = found1 + 4; j < i; j++)
cout << str[j];
cout << "." << endl;
//found1 = i;
break;
}
if(str[i] == '.')
{
//found1 = i;
break;
}
}
found1 = str.find(str1, found1 + (i - 4 - found1));
}
}
}