Topic 1049 string to specific character 9 degree Online Judge

Source: Internet
Author: User

Topic 1049 string to specific character 9 degree Online Judge
Description:

The input string s and character c must be removed from all the c characters in s and output results.

Input:

There are multiple groups of test data, with each group of input strings s and character c.

Output:

For each group of inputs, the output results after the c characters are removed.

Sample input:
healloa
Sample output:
hello

Method 1:

 

# Include
 
  
# Include
  
   
Using namespace std; int main () {string s; // ×ö· û'®While (cin> s) {char c; cin> c; for (int I = 0; I <s. length (); I ++) {if (s [I]! = C) {cout <
   
    
Method 2:
    

 

 

/* This idea: compare two string arrays. If the two strings are the same, replace them with a specific character. Because it is a string, it is special, so choose to replace it with '\ n! The question is why we use getline when we try again. The result displayed for the first time is correct. It is incorrect when we perform the second test! If you are interested, try it on your own. */# Include
     
      
# Include
      
       
Using namespace std; int main () {string str1, str2; int I, j; // while (cin, str1) while (cin> str1) {int x = I; // getline (cin, str2); // I don't know why. When getline is used in the while loop, the first comparison is correct. The second comparison is incorrect! // If Daniel knows, please let me know! Cin> str2; for (int I = 0; I
       
        

 

Related Article

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.