Topic 1159: Word substitution

Source: Internet
Author: User

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.


Enter 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 only 1 rows per test data output, replacing all word a in s with the string after B.


Sample input

I Love Tian Qin
I
You

Sample output
You love Tian Qin

hint [+]

Tip is hidden, click above [+] to show * * *
Source

2007 Peking University computer Research Life Test real problem

/*********************************
*   Date: 2013-4-5
*   Author: SJF0115
*   title number: Title 1159: Word Substitution
*   Source: http://acmclub.com/problem.php?id=1159
*   Result: AC
*   Source: Tian Qin OJ
*   Summary:
****** /
#include <stdio.h>
#include <stdlib.h>
#include < string.h>

int main ()
{
	int i,j,index,len,len2;
	Char str[101],word[101],newword[101],temp[101];
	Freopen ("C:\\users\\sjf\\desktop\\acm.txt", "R", stdin);  
	while (gets (str)) {
		index = 0;
		len = strlen (str);
		scanf ("%s", word);
		scanf ("%s", Newword);
		for (i = 0;i <= len;i++) {
			if (str[i] = = "| | i = len) {
				Temp[index] = ' + ';
				if (strcmp (temp,word) = = 0) {
					printf ("%s", Newword);
				}
				else{
					printf ("%s", temp);
				}
				if (str[i] = = ") {
					printf (" ");
				}
				else{
					printf ("\ n");
				}
				index = 0;
				memset (temp,0,sizeof (temp));
			}
			else{
				temp[index++] = Str[i];
			}
		}
		GetChar ();
	}
	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.