一道简单的大一oj吧

img

img

https://blog.csdn.net/u014377763/article/details/113737130


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
using namespace std;
string remove(string s, char c)
{
       int i;
    string ans = "";
    for (i = 0; i < s.length(); i++)
        if (s[i] != c)
            ans += s[i];
    return ans;
}
string remove(string s, int n)
{
        int i;
    int l = s.length();
    l--;
    if (n > l || n < 0)
        return s;
    string ans = "";
    for (i = 0; i < n; i++)
        ans += s[i];
    for (i = n + 1; i <= l; i++)
        ans += s[i];
    return ans;
}
string remove(string s, int x, int y)
{
      int i;
    int l = s.length();
    l--;
    if (x > l || x < 0 || y>l || y<0 || x>y)
        return s;
    string ans = "";
    for (i = 0; i < x; i++)
        ans += s[i];
    for (i = y + 1; i <= l; i++)
        ans += s[i];
    return ans;
}
int main()
{
    int num, index, startIndex, endIndex;
    char delChar;
    string src, dest;
 
    while (cin >> num)
    {
        switch (num)
        {
        case 1:
            cin >> src >> delChar;
            cout << remove(src, delChar) << endl;
            break;
        case 2:
            cin >> src >> index;
            cout << remove(src, index) << endl;
            break;
        case 3:
            cin >> src >> startIndex >> endIndex;
            cout << remove(src, startIndex, endIndex) << endl;
            break;
        }
    }
    return 0;
}

兄弟你贴问题的时候不能贴代码吗,图片很不清楚啊