L1-059 Knock the clock (20 minutes)||Do it with string functions

There is a guy on Weibo who calls himself "Big Ben V", ringing the bell every day to urge code farmers to take care of their bodies and go to bed early. In order to increase the fun of ringing the bell, a few ancient poems will be changed. The way to change it is to search the Internet for ancient poems with "ong" rhymes, and replace the three characters at the end of the sentence with "knock the clock". For example, the poet Li He of the Tang Dynasty famously said: "Looking for chapters and extracting sentences from old carvings and insects, and the moon as the curtain hangs a jade bow", in which "chong" (chong) and "gong" (gong) both suppress the rhyme of "ong". So this line of poem was changed to "Looking for chapters and excerpts the old eagle-worm, and the morning moon as the curtain knocks the clock".

Now I will give you a lot of ancient poems and sentences and ask you to write a program to automatically change the "ong" rhyme sentences into "knock the clock".

Input format:
Input a positive integer N not exceeding 20 in the first line of input. After N lines, each line gives a sentence of ancient poems in Chinese pinyin, divided into upper and lower half sentences, separated by commas, and ending with a period. Use a space to separate the pinyin of two adjacent characters. The title guarantees that the pinyin of each word does not exceed 6 characters, the total length of each line of characters does not exceed 100, and the second half of the poem has at least 3 characters.

Output format:
For each line of verse, judge whether it has an "ong" rhyme. That is, the words at the end of the upper and lower sentences all end with "ong". If it is the rhyme, it will be output according to the method of the title, and the output format will be the same as the input; otherwise, if the output is Skipped, the sentence will be skipped.

Input sample:

5
xun zhang zhai ju lao diao chong, xiao yue dang lian gua yu gong.
tian sheng wo cai bi you yong, qian jin san jin huan fu lai.
xue zhui rou zhi leng wei rong, an xiao chen jing shu wei long.
zuo ye xing chen zuo ye feng, hua lou xi pan gui tang dong.
ren xian gui hua luo, ye jing chun shan kong.

Sample output:

xun zhang zhai ju lao diao chong, xiao yue dang lian qiao ben zhong.
Skipped
xue zhui rou zhi leng wei rong, an xiao chen jing qiao ben zhong.
Skipped
Skipped
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
    
    
	int T;
	cin >> T;
	getchar();
	while(T--)
	{
    
    
		string a;
		getline(cin,a);
		int flag = 0;
		string str1("ong,");
		string str2("ong.");
		if(a.find(str1) != string::npos) flag = 1;
		if(a.find(str2) != string::npos  && flag == 1)
		{
    
    
			int res = 0,ans = 0;
			for(int i = a.length() - 1;; i --)
			{
    
    
				if(a[i] == ' ')
					res ++;
				if(res == 3)
				{
    
    
					ans = i;
					break;
				}	
			}
			cout << a.substr(0,ans) << " qiao ben zhong." << endl;
		}
		else
		cout << "Skipped" << endl;
	}
	
	return 0;
} 

Guess you like

Origin blog.csdn.net/diviner_s/article/details/108784985