11 条题解

  • 8
    @ 2022-8-8 21:19:32
    ···
    char c;
    short cnt[8];
    ···
        ···
        while(cin>>c){ // 依次读入每个字符并判断是否为需要字符
            if(c=='h')cnt[1]=1;
            else if(c=='e')cnt[2]=1;
            else if(c=='t')cnt[3]=1;
            else if(c=='a')cnt[4]=1;
            else if(c=='o')cnt[5]=1;
            else if(c=='1')cnt[6]++; // 需要两个1所以要用++而不是纯粹的赋值=
            else if(c=='0')cnt[7]=1;
        }
        cnt[1]&&cnt[2]&&cnt[3]&&cnt[4]&&cnt[5]&&cnt[6]>=2&&cnt[7]?cout<<"hetao101":cout<<"so sad!"; // 三目运算符判断并输出结果
        ···
    ···
    
    • @ 2022-9-12 18:54:14

      其实采用这种方法似乎也可以……(复制快乐)

      #include<bits/stdc++.h>
      using namespace std;
      int a[7];
      int main(){
          string s;
          cin>>s;
          if(s.length()<=1000){
              for(int i=0;i<s.length();i++){
                  if(s[i]=='h'){
                      a[1]=1;
                  }else if(s[i]=='e'){
                      a[2]=1;
                  }else if(s[i]=='t'){
                      a[3]=1;
                  }else if(s[i]=='a'){
                      a[4]=1;
                  }else if(s[i]=='o'){
                      a[5]=1;
                  }else if(s[i]=='0'){
                      a[6]=1;
                  }else if(s[i]=='1'){
                      a[7]++;
                  }
            }
            if(a[1]==1&&a[2]==1&&a[3]==1&&a[4]==1&&a[5]==1&&a[6]==1&&a[7]==2){
                cout<<"hetao101";
            }else{
                cout<<"so sad!";
            }
          }
            
          return 0;
      }
      
    • @ 2024-1-20 11:29:08

      似乎不大行,按照你的代码1出现的次数如果是2次以上就不行,得把a[7]==2改成a[7]>=2

  • 7
    @ 2023-9-29 12:59:33

    非常暴力

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a[9];
        memset(a, 0, sizeof(a));
        string s;
        cin >> s;
        for (int i = 0; i < s.length(); i++)
        {
            if (s[i] == 'h')
                a[1] = 1;
            if (s[i] == 'e')
                a[2] = 1;
            if (s[i] == 't')
                a[3] = 1;
            if (s[i] == 'a')
                a[4] = 1;
            if (s[i] == 'o')
                a[5] = 1;
            if (s[i] == '0')
                a[6] = 1;
            if (s[i] == '1')
                a[7]++;
        }
        if (a[1] == 1 && a[2] == 1 && a[3] == 1 && a[4] == 1 && a[5] == 1 && a[6] == 1 && a[7] >= 2)
            cout << "hetao101";
        else
            cout << "so sad!";
        return 0;
    }
    
    • 4
      @ 2022-10-30 11:02:13

      嗨害嗨,本题不必大费周章:list+count()(python3),上代码:

      a=list(input())
      if a.count('h') >= 1 and a.count('e') >= 1 and a.count('t') >= 1 and a.count('a') >= 1 and a.count('o') >= 1 and a.count('1') >= 2 and a.count('0') >= 1:#判断有无'h','e','t','a','o','1','0','1'
      print('hetao101')
      else:
      print('so sad!')
      

      Loading:8/100……

      • @ 2024-1-23 23:14:12

        另外一种方法,打字量会少一点

        a = list(input())if("h" in a) and ('e' in a) and ('t' in a) and ('a' in a) and ('o' in a) and ('0' in a) and (a.count('1') >= 2):```
        print("hetao101")else:    print('so sad!')
        

        不用打这么多个

        a.count()
        

        可以用

        in
        

        代替

      • @ 2024-1-24 21:49:27

        另外一种舒服点的写法:

        a = list(input())
        if("h" in a) and ('e' in a) and ('t' in a) and ('a' in a) and ('o' in a) and ('0' in a) and (a.count('1') >= 2):
            print("hetao101")
        else:
            print('so sad!')
        

        不用打这么多个a.count(),前面的可以用in代替

    • 3
      @ 2022-9-21 20:04:26

      发个题解玩玩 可能我写的不是最短的,但是也能解出来

      #include <bits/stdc++.h>
      #include <cstring>
      using namespace std;
      int main()
      {
          int onege = 0;
          bool hetao101[10] = {false,false,false,false,false};
          string n;
          cin >> n;
          int v;
          v = n.length();
          for (int i = 0;i <= v;i++)
          {
              if(n.substr(i,1)=="h")
              {
                  hetao101[0] = true;
              }
              if(n.substr(i,1)=="e")
              {
                  hetao101[1] = true;
              }
              if(n.substr(i,1)=="t")
              {
                  hetao101[2] = true;
              }
              if(n.substr(i,1)=="a")
              {
                  hetao101[3] = true;
              }
              if(n.substr(i,1)=="o")
              {
                  hetao101[4] = true;
              }
              if(n.substr(i,1)=="1")
              {
                  hetao101[5] = true;
                  onege++;
              }
              if(n.substr(i,1)=="0")
              {
                  hetao101[6] = true;
              }   
          }
          if (hetao101[0] == true && hetao101[1] == true && hetao101[2] == true && hetao101[3] == true && hetao101[4] == true && hetao101[5] == true && hetao101[6] == true && onege >= 2)
          {
              cout << "hetao101" << endl;
          }
          else
          {
              cout << "so sad!" << endl;
          }
      }
      
      • 2
        @ 2023-4-26 22:04:39

        直接暴力

        #include<bits/stdc++.h>
        using namespace std;
        int a[10];
        string s;
        int main()
        {
            cin>>s;
            for (int i=0;i<s.length();i++)
            {
                if (s[i]=='h')
                    a[1]++;
                if (s[i]=='e')
                    a[2]++;
                if (s[i]=='t')
                    a[3]++;
                if (s[i]=='a')
                    a[4]++;
                if (s[i]=='o')
                    a[5]++;
                if (s[i]=='1')
                    a[6]++;
                if (s[i]=='0')
                    a[7]++;
            }
            if (a[1]>0&&a[2]>0&&a[3]>0&&a[4]>0&&a[5]>0&&a[6]>=2&&a[7]>0)
                cout<<"hetao101";
            else
                cout<<"so sad!";
            return 0;
        }
        • 2
          @ 2023-3-3 12:10:53
          #include<bits/stdc++.h>
          using namespace std;
          int main(){
              string s;
              int num=0,num1=0,num2=0,num3=0,num4=0,num5=0,num6=0;
              cin>>s;
              for(int i=0;i<s.length();i++){
                  if(s[i]=='1'){
                      num++;
                  }
                  if(s[i]=='h'){
                      num1++;
                  }
                  if(s[i]=='e'){
                      num2++;
                  }
                  if(s[i]=='t'){
                      num3++;
                  }
                  if(s[i]=='a'){
                      num4++;
                  }
                  if(s[i]=='o'){
                      num5++;
                  }
                  if(s[i]=='0'){
                      num6++;
                  }
              }
              for(int i=0;i<s.length();i++){
                  if(num>=2&&num1>=1&&num2>=1&&num3>=1&&num4>=1&&num5>=1&&num6>=1){
                      cout<<"hetao101";
                      return 0;
                  }
              }
              cout<<"so sad!";
          }
          
          • 1
            @ 2023-12-15 19:49:39

            单纯使用if判断即可

            #include <bits/stdc++.h>
            using namespace std;
            int a[10];
            int main()
            {
                /* 此处为对应关系
                h -> a[1]
                e -> a[2]
                t -> a[3]
                a -> a[4]
                o -> a[5]
                1 -> a[6]
                0 -> a[7]
                */
                string s;
                cin >> s;
                int sl = s.length(); // 实际可以写于循环 sl 处,此处为了避免Linux系统编译器:D
                for (int i = 0; i < sl; i++)
                {
                    if (s[i] == 'h') // 判断是否是 h
                        a[1]++;
                    else if (s[i] == 'e') // 判断是否是 e
                        a[2]++;
                    else if (s[i] == 't') // 判断是否是 t
                        a[3]++;
                    else if (s[i] == 'a') // 判断是否是 a
                        a[4]++;
                    else if (s[i] == 'o') // 判断是否是 o
                        a[5]++;
                    else if (s[i] == '1') // 判断是否是 1
                        a[6]++;
                    else if (s[i] == '0') // 判断是否是 0
                        a[7]++;
                }
                if (a[1] >= 1 && a[2] >= 1 && a[3] >= 1 && a[4] >= 1 && a[5] >= 1 && a[6] >= 2 && a[7] >= 1) // 判断是否能组成 hetao101
                    cout << "hetao101";
                else
                    cout << "so sad!";
                return 0;
            }
            

            最后一个判断的代码单独列于下方 if (a[1] >= 1 && a[2] >= 1 && a[3] >= 1 && a[4] >= 1 && a[5] >= 1 && a[6] >= 2 && a[7] >= 1)

            if (a[1] >= 1 && a[2] >= 1 && a[3] >= 1 && a[4] >= 1 && a[5] >= 1 && a[6] >= 2 && a[7] >= 1)
            
          • 0
            @ 2024-1-20 11:27:22

            发个暴力解法

            #include
            using namespace std;
            int a[6],ans;
            int main(){
                string s;
                cin>>s;
                for(int i=0;i<s.length();i++){
                    if(s[i]==104){
                    //scall码,用'h'是一样的效果
                    //以下同理
                        a[0]++;
                    }
                    if(s[i]==101){
                        a[1]++;
                    }
                    if(s[i]==116){
                        a[2]++;
                    }
                    if(s[i]==97){
                        a[3]++;
                    }
                    if(s[i]==111){
                        a[4]++;
                    }
                    if(s[i]==49){
                        a[5]++;
                    }
                    if(s[i]==48){
                        a[6]++;
                    }
                }for(int i=0;i<7;i++){
                    if(a[i]>0 and i!=5){
                    //除了1以外的字符出现过
                        ans++;
                    }else if(a[i]>1){
                    //hetao101中1出现了两次
                    //所以要1的数量大于1
                        ans++;
                    }
                }
                if(ans==8){
                //这里我也不知道为什么ans==7过不去
                //但是ans==8能过去
                    cout<<"hetao101";
                }else{
                    cout<<"so sad!";
                }
                return 0;
            }
            
            • 0
              @ 2023-11-25 20:12:23

              已AC,放心用

              #include<bits/stdc++.h>
              using namespace std;
              bool a[9];//判断‘hetao101’中每个字符是否出现
              int main()
              {
                  string s;
                  cin>>s;
                  int num=0;
                  bool flag=false;//判断是否输出“so sad!”
                  for(int i=0;i<s.length();i++)//因为s的长度很小,直接暴力枚举
                  {
                      if(((a[1]&&a[2])&&(a[3]&&a[4]))&&((a[5]&&a[6])&&(a[7]&&num>=2)))//判断是否输出“hetao101”
                      {
                          cout<<"hetao101";
                          flag=true;
                          break;
                      }
                      else if(s[i]=='h')//判断是否出现“hetao101”中的字符
                      {
                          a[1]=true;
                      }
                      else if(s[i]=='e')
                      {
                          a[2]=true;
                      }
                      else if(s[i]=='t')
                      {
                          a[3]=true;
                      }
                      else if(s[i]=='a')
                      {
                          a[4]=true;
                      }
                      else if(s[i]=='o')
                      {
                          a[5]=true;
                      }
                      else if(s[i]=='1')
                      {
                          a[6]=true;//题目中的小坑,1要出现两次
                          num++;
                      }
                      else if(s[i]=='0')
                      {
                          a[7]=true;
                      }
                  }
                  if(flag)
                  {
                      int y=0;
                  }
                  else{
                      cout<<"so sad!";
                  }
              }
              
            • 0
              @ 2022-7-20 17:27:41

              #include<bits/stdc++.h> using namespace std; int main() { int l[8];//定义一个数组,表示收集到的每个符合要求的字符的数量 memset(l,0,sizeof(l));//初始化列表 string n,ans="hetao101";//定义输入的字符串和需要组成的字符串 cin>>n;//输入字符串 int w=n.length(); //这一行代码目的是转换n.length()的数据形式,从无符号数转为有符号数,避免报错 for(int i=0;i<w;i++)//遍历输入的字符串 { for(int j=0;j<8;j++)//遍历需要组成的字符串,找到当前n[i]是否存在于"hetao101"中 { if(ans[j]==n[i]&&l[j]==0)//判断当前遍历到的输入字符串中的字符是否和需要组成的字符串中的某一字符相等,并且未找到过对应的字符 { l[j]++;//如果满足上述条件,则找到符合要求的字符数量+1 break;//找到结果后终止内循环,防止"hetao101"中的两个1被同时增加 } } } bool flag=true;//定义一个布尔值,表示最终判断结果,默认为真 for(int i=0;i<8;i++) { if(l[i]==0)//判断是否未找到对应的字符 { flag=false;//若未找到,将结果设为假 } } if(flag)//如果找全了所有需要的字符,那么输出"hetao101",否则输出"so sad!" { cout<<"hetao101"; } else { cout<<"so sad!"; } return 0; }

              • -7
                @ 2022-4-24 16:43:10

                写题解请注意

                鼓励大家写题解,但注意题解格式。

                题解一定要有思路解析或代码注释,能否让别人理解你的思路

                也是你的能力的检验,不要只放无意义的代码给大家复制,那就失去了做题的初心。

                给代码两端加上这个会舒服一些

                ```cpp

                你的代码

                ```

                </span>

                这个点在键盘的左上角tab上面那个键,注意切换输入法

                #include<iostream>
                using namespace std;
                int main()
                {
                    int n;
                    cin>>n;//这是一个注释
                    return 0;
                } 
                

                请注意严禁抄袭题解,写题解不要只放代码,需加上你的思路或代码注释。

                抄袭题解一经发现直接取消成绩。

                题解被删除的可能

                1. 代码不符合格式规范
                2. 没有思路讲解或者没有注释,
                3. 无意义的题解

                大家携手共同维护一个良好的编程环境,如果一经发现,多次作乱。可能会被管理员拉黑,请注意,一旦拉黑即失去登陆资格。

                • 1

                信息

                ID
                1243
                时间
                1000ms
                内存
                256MiB
                难度
                8
                标签
                递交数
                6548
                已通过
                822
                上传者