String handling: Monkey Typing

Source: Internet
Author: User

Zhejiang Zoo has recently hired a number of program apes, and zoo managers hope to develop these apes as future Nobel, Turing and fields prizes. To this end, the zoo for the Apes launched a special training: writing articles.

In a recent exercise, the monkeys randomly knocked out strings that were no more than 5000 in length, each of which was random from the spaces, half-width punctuation marks, numbers, and the 95 printable characters of the English case.

Administrators believe that if the "Nature & Science" substring (without quotes and case sensitivity) appears in the String, the apes have achieved the training goal of publishing the entire contents of the first "Nature & Science" as an article, For the world to behold. Input format

An integer T that indicates how many sets of test data are available.

The next T line, each line has a string. Note The string may contain spaces, so it is recommended that you read in GetChar () or other similar ways. Output format

For each set of test data, if the monkeys were able to publish an article, they would output a line of string representing the contents of the article, otherwise doing nothing. Sample input

4
) #>alv.riqq;ik3&[<>$
Hello, Nature & Science:world Nature
& Science:hello, world< C3/>the Cake is a Lie. Nature & Science.
Sample output
Hello, 

Tips

There is no "nature & Science" in the first set of data, so there is no output.

"Nature & Science" appeared in the remaining sets of data, but the third set of data had no characters before "Nature & Science", so a blank line was exported.

In addition, in order to illustrate the output, some of the sample data is constructed by the zoo administrator, but we guarantee that the actual test data are all written by the apes and strictly conform to the conditions guaranteed in the title description.


#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main () {
	int T;
	String str;
	Cin >> T;
	GetChar ();
	while (t--) {
		getline (cin, str);
		int pos = Str.find ("Nature & Science");
		if (pos >= 0) {
			for (int i = 0; i < POS; i++) {
				printf ('%c ', str[i]);
			}
			printf ("\ n")
		;
	}
	return 0;
}




#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main () {
	int T;
	String str;
	scanf ("%d", &t);
	GetChar ();
	while (t--) {
		getline (cin, str);
		int pos = Str.find ("Nature & Science");
		if (pos = 0) printf ("\ n");
		if (pos > 0 && pos < 5010) {
			str = str.substr (0, POS);
			printf ("%s\n", Str.c_str ());
			cout << str << endl;
		}
	return 0;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.