Blue Bridge Cup ALGO-89 character Delete (string)

Source: Internet
Author: User

"Idea": Use string replace method on the line, pay attention to the topic " inside no space", is not inside. So you need to consider the case where the string is empty or there are spaces around it. You can't use CIN anymore, you need to use gets and so on. So you need to convert char[] into a string step. In addition, Char cannot define a character on the same line and then define a string. Conversely, you might not get a character pointer to a character error.

"AC Code":

#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <  Cstring>using namespace Std;int Main () {//freopen ("In.txt", "R", stdin); int i = 0;char ss[100], c;gets (ss); Cin >> c;string str = ss;for (i = 0; i < str.length (); i++) {if (str[i] = = c) {str.replace (I, 1, ""); i--;}} cout << str;}


Blue Bridge Cup ALGO-89 character Delete (string)

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.