Uva_10115-Automatic Editing

Source: Internet
Author: User

[Cpp]
/** The meaning of this question is to convert the previous string into the next string, the current string
* If no result is found, compare the Next string until all strings are replaced.
*/
# Include <cstdio>
# Include <iostream>
# Include <cstring>
Using namespace std;
 
# Deprecision MAX 256
 
// Replace
Void replace (char * a, char * B, int pos ){
For (int I = 0; I <strlen (a); I ++ ){
B [pos ++] = a [I];
}
}
 
// Search for substrings
Int findSon (char * s1, char * s2, int & start, int & end ){
Int j, i1;
For (int I = 0; I <strlen (s2); I ++ ){
I1 = I;
For (j = 0; j <strlen (s1); j ++ ){
If (s1 [j]! = S2 [i1 ++]) break;
}
If (j = strlen (s1 )){
Start = I; end = I + J-1; return 1;
}
}
Return 0;
}
 
 
Int main (int argc, char const * argv []) {
Int cas, start, end, len, flag;
Char data [MAX];
Char word [MAX] [MAX];
While (cin> cas, cas! = 0 ){
Getchar ();
For (int I = 0; I <2 * cas; I + = 2 ){
Gets (word [I]);
Gets (word [I + 1]);
}
Gets (data );
For (int I = 0; I <2 * cas; I + = 2 ){
Flag = 1;
While (flag ){
Flag = findSon (word [I], data, start, end );
Len = strlen (word [I])-strlen (word [I + 1]);
// Whether there are replaceable strings in the flag ID. The following code replaces the strings without using library functions.
If (flag ){
If (len <0 ){
Len =-len;
For (int I = strlen (data); I> end; I --){
Data [I + len] = data [I];
}
} Else if (len> 0 ){
For (int I = end-len + 1; I <strlen (data); I ++ ){
Data [I] = data [I + len];
}
}
Replace (word [I + 1], data, start );
}
}
 
}
Puts (data );
}
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.