应该怎么简化啊
查看原帖
应该怎么简化啊
268346
only76楼主2020/5/27 17:33
#include<cstdio>
#include<iomanip>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include <string>
#include<cmath>
using namespace std;
string n;
int boy,girl;
int main()
{
    getline(cin, n);
    for(int i=0; i<n.size(); i++)
    {
        if(n[i]=='b'&&n[i+1]!='o')
        {
            boy++;
        }
        if(n[i]=='o'&&n[i+1]!='y'&&n[i-1]!='b')
        {
            boy++;
        }
        if(n[i]=='y'&&n[i-1]=='o'&&n[i-2]=='b')
        {
            boy++;
        }
        if(n[i]=='y'&&n[i-1]!='o')
        {
            boy++;
        }
        if(n[i]=='b'&&n[i+1]=='o'&&n[i+2]!='y')
        {
            boy++;
        }
        if(n[i]=='o'&&n[i+1]=='y'&&n[i-1]!='b')
        {
            boy++;
        }
        if(n[i]=='g'&&n[i+1]!='i')
        {
            girl++;
        }
        if(n[i]=='i'&&n[i+1]!='r'&&n[i-1]!='g')
        {
            girl++;
        }
        if(n[i]=='r'&&n[i+1]!='l'&&n[i-1]!='i')
        {
            girl++;
        }
        if(n[i]=='l'&&n[i-1]!='r')
        {
            girl++;
        }
        if(n[i]=='g'&&n[i+1]=='i'&&n[i+2]!='r')
        {
            girl++;
        }
        if(n[i]=='i'&&n[i+1]=='r'&&n[i-1]!='g'&&n[i+2]!='l')
        {
            girl++;
        }
        if(n[i]=='r'&&n[i+1]=='l'&&n[i-1]!='i'&&n[i-2]!='g')
        {
            girl++;
        }
        if(n[i]=='g'&&n[i+1]=='i'&&n[i+2]=='r'&&n[i+3]!='l')
        {
            girl++;
        }
        if(n[i]=='i'&&n[i+1]=='r'&&n[i+2]=='l'&&n[i-1]!='g')
        {
            girl++;
        }
        if(n[i]=='g'&&n[i+1]=='i'&&n[i+2]=='r'&&n[i+3]=='l')
        {
            girl++;
        }
    }
    cout<<boy<<endl<<girl;

}


2020/5/27 17:33
加载中...