1111. Application of Word substitution strtok function

Source: Internet
Author: User
Tags strtok

Title Description:

Enter a string to end with a carriage return (string length <=100). The string consists of several words, separated by a space, and all the words are case-sensitive. Now you need to replace one of these words with another word and output the replaced string.

Input:
Multiple sets of data. Each set of data input consists of 3 rows, the 1th line is a string with multiple words, the 2nd line is the word a to be replaced, and (length <=100) line 3rd is the word b that will be replaced. (length <=100) s, a, b the front and the back have no spaces.

Output:
Each test data output has only 1 rows, replacing all word a in s with the string after B.

Sample input:
Want someone to help Youyoui
Sample output:
I want someone to help you

#include <iostream>#include<cstring>using namespacestd;intMain () {Chars[ -],a[ -],b[ -];  while(gets (s)) {gets (a);        Gets (b); intflag=1; Char*temp=strtok (s)," ");  while(temp) {if(flag) flag=0; Elsecout<<" "; if(strcmp (temp,a) = =0) cout<<b; Elsecout<<temp; Temp=strtok (NULL," "); } cout<<Endl; }    return 0;}

1111. Application of Word substitution strtok function

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.