Ultraviolet A 10115-automatic editing

Source: Internet
Author: User

The general meaning is to replace the strings in the first column of the list with the strings in the second column until all the strings in the entire sentence are replaced, then replace the Next string. The question itself is not difficult. I believe that if you take it seriously, you can easily AC it ~

(If strstr () and sprintf functions are usedCodeA lot of conciseness and efficiency will be improved. Of course, if STL string is used, it will be very fast .)

The Code is as follows:

 # include 
  
    # include 
   
     # include 
    
      int main () {# ifdef sta freopen ("sample. text "," r ", stdin); # endif int K, I; char * ffct; // define a character pointer char sum [20 + 1] [80 + 1], A [260], B [260], C [260]; while (scanf ("% d", & K) {getchar (); If (k = 0) break; memset (sum, 0, sizeof (SUM); memset (A, 0, sizeof (a); memset (B, 0, sizeof (B )); for (I = 0; I <= 2 * K-1; I ++) gets (sum [I]); gets (a); for (I = 0; I <= 2 * K-1; I = I + 2) while (1) {ffct = strstr (A, sum [I]); // find the place where the string to be replaced appears if (ffct = NULL) break; sprintf (C, "% s", ffct + strlen (sum [I]); // Save the strings behind the replacement part to sprintf (ffct, "% s", sum [I + 1]) in the C array. // Replace the part to be replaced (the string after replacement is overwritten) sprintf (ffct + strlen (sum [I + 1]), "% s ", c); // Add the temporary string} printf ("% s \ n", a);} 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.