小h的题目

题目描述

每个人都在担心考试的难度。 小h有一个规则来出题目,他会在写问题之前写一个随机字符串

只要可以按顺序在此字符串中找到四个字母E,A,S,Y。 他的题目会很容易。

现在你有这个字符串,请告诉我测试题的难度。

输入

输入数据有多组,每组占用一行,由一个字符串 s t r str str组成( 1 ≤ l e n ( s t r ) ≤ 1000 1 \leq len(str) \leq1000 1len(str)1000

输出

对于每组输入,输出一行。

题目很容易输出easy,否则输出difficult。

样例输入 Copy

eAsy
SEoAtSNY

样例输出 Copy

difficult
easy
ps:法1:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    
    
    string str;
    while (cin >> str)
    {
    
    
        int m = str.find("E");
        int a = 0;
        int b = 0;
        int c = 0;
        if (str.find("E") < str.size() && str.find("A") < str.size() && str.find("S") < str.size() && str.find("Y") < str.size())
        {
    
    
            m = m + 1;
            for (; str[m] != '\0'; m++)
            {
    
    
                if (str[m] == 'A')a = m;
                if (str[m] == 'S' && m > a && a != 0 )b = m;
                if (str[m] == 'Y' && m > b && b != 0 )c = m;
            }
            if (a != 0 && b != 0 && c != 0)cout << "easy" << endl;
            else cout << "difficult" << endl;
        }
        else cout << "difficult" << endl;
    }
}

法2:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
char t[]={
    
    'E','A','S','Y'};//用全局数组指针存放这些元素,注意也得要满足题目给的顺序
int main(){
    
    
    string s;
    while(cin>>s){
    
    
        int k=0;
        for(int i=0;i<s.size();i++){
    
    
            if(s[i]==t[k])k++;//按顺序找到一个则下标+1
            if(k==4)break;
        }
        if(k==4)cout<<"easy"<<endl;
        else cout<<"difficult"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_52297656/article/details/115603442