文章

27

粉丝

86

获赞

10

访问

30.5k

头像
删除字符串2 题解:
P1027 贵州大学2019机试
发布于2023年8月14日 16:42
阅读数 1.2k

C++

一开始写的代码

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    getline(cin, s);
    string target1 = "gzu";
	string target2 = "gzU";
	string target3 = "gZu";
	string target4 = "gZU";
	string target5 = "Gzu";
	string target6 = "GzU";
	string target7 = "GZu";
	string target8 = "GZU";
    size_t pos1 = s.find(target1);
	size_t pos2 = s.find(target2);
	size_t pos3 = s.find(target3);
	size_t pos4 = s.find(target4);
	size_t pos5 = s.find(target5);
	size_t pos6 = s.find(target6);
	size_t pos7 = s.find(target7);
	size_t pos8 = s.find(target8);
    while (pos1 != string::npos) {
        s.erase(pos1, 3);
        pos1 = s.find(target1);
    }
	while (pos2 != string::npos) {
        s.erase(pos2, 3);
        pos2 = s.find(target2);
    }
    while (pos3 != string::npos) {
        s.erase(pos3, 3);
        pos3 = s.find(target3);
    }
	while (pos4 != string::npos) {
        s.erase(pos4, 3);
        ...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发