当前位置:网站首页>7-7 ring the stupid bell

7-7 ring the stupid bell

2022-07-06 16:44:00 HBUcs2020

Topic link :PTA | Program design experiment auxiliary teaching platform

Mainly to investigate string Various uses of , The question is not difficult

// character string 
// String search and replacement 
#include<iostream>
using namespace std;
#include<string>
int main()
{
    int n,pos1,pos2;
    cin>>n;
    getchar();
    while(n--)
    {
        string s;
        getline(cin,s);
        pos1=s.find("ong,");
        pos2=s.find("ong.");
        if(pos1!=1&&pos2!=-1)
        {
            int count=0;  // Record the number of spaces 
            int i;
            for(i=s.length()-1; i>=0; i--)
            {
                if(s[i]==' ')
                    count++;
                if(count==3)
                    break;  // here i by ' ' The location of 
            }
            s.replace(i,s.length()-i," qiao ben zhong");
            cout<<s<<endl;
        }

        else
            cout<<"Skipped"<<endl;
    }
    return 0;
}

原网站

版权声明
本文为[HBUcs2020]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131314584039.html