problem 2122 See also lkityaccept:407 submit:1413
Time limit:1000 mSec Memory limit:32768 KB problem Description
Hey! Hello everyone, everyone knows me in the Templerun. I am a stupid and poor cat lkity. I'm glad to meet you again Fzu Acmer. Recently See Fzu all the Acmer are in the hard training, all day in the sun idle Panic of my pressure mountain Ah! So, I am prepared for you to write a gadget--lkity brand text replacement (outrage: dare not to be more earth point!) )。 This gadget can help you replace the variables in the code and other functions, is really a programming, brush the subject of the necessary artifact. The functions are as follows:
Replaces all of the given substring with a given string, given a sequence of characters. To make it more powerful, the case is ignored during the replacement process. And does not perform recursive substitution operations.
However, as a stupid cat, I am powerless! I hope you acmer can help me achieve ha. (Fzu's Acmer: "...");
The input input contains multiple sets of data. Input is a standard input and the input contains 3 rows. The first behavior needs to find the string S1. The S1 is made up of only uppercase or lowercase letters, and its length is within the interval [1,,100]. The second behavior is to replace the string S2. S2 is made up of [32,125] characters, and its length is within the interval [1,100]. The third behavior of the original string s,s consists of the characters [32,125]. And its length is within the range [1,50,000]. output for each set of data, output the replaced string. sample inputabcbc abaaa aaabca 333abcc## sample outputaaa aabc aba 333BC abc## SOURCE Fuzhou University tenth session design contest problem solving ideas: using two pointers i,j respectively to the TXT array and the P array, txt if there is a match to the P array, the output. Otherwise, the I pointer is rolled back to the position where it was first matched. was a two or three-hour pit-drunk.
#include <stdio.h> #include <algorithm> #include <math.h> #include <string.h> #include < string>using namespace Std;const int maxn = 1e5+200;char P[1020],txt[maxn],rpl[1020];bool Jud (char A, char b) {if (a = = B) {return true; }else{if (a>= ' a ' &&a<= ' Z ') {if (b>= ' a ' &&b<= ' Z ') {if (a-32 = = b) return true; }} if (a>= ' a ' &&a<= ' Z ') {if (b>= ' a ' &&b<= ' Z ') {if (a+32 = = b) return true; }}} return false;} int main () {while (gets (p)!=null) {gets (RPL); Gets (TXT); int LENP = strlen (p); int lenr = strlen (RPL); int lent = strlen (TXT); int I, J; for (i = 0, j = 0; i < lent; i++) {if (Jud (P[j],txt[i])) {j + +; if (j = = LENP) {for (int k = 0; k < lenr; k++) { printf ("%c", Rpl[k]); } j = 0; }}else{I-= j; Rewind i pointer j = 0; printf ("%c", Txt[i]); }} for (int k = lent-j; k < lent; k++) {printf ("%c", Txt[k]); } puts (""); } return 0;} /*aabkkaaabaabkkabaa*/
Fzu 2122--See also lkity —————— "string match, violence"