weixin_51140667 2022-09-23 04:07 采纳率: 75%
浏览 18

大lao帮我看看力扣meituan-001为啥只过了一个用例

大lao帮我看看我的屎山meituan-001为啥只过了一个用例

提目:https://leetcode.cn/problems/BaR9fy/


#include<iostream>
using namespace std;

int main()
{
    //cout << "先输入循环次数再给爷几个数:";
    string temp;
    int temp2,temp3;
    int l;
    start:;
    cin >> l;//题意输入几个名字
    if (!cin) { cout << "Wrong"<<endl;cin.clear(); cin.ignore(1024, '\n');goto start; }
    for (int i = 0; i < l; i++)//题意输入几个名字就循环几次
    {
        cin >> temp;
        if (!cin) { cout << "Wrong"<<endl; cin.clear(); cin.ignore(1024, '\n'); continue; }
        int shuzi_num = 0;
        int zimu_num = 0;
        int succeed=0;
        for (int i = 0; i < temp.size(); i++)
        {
            succeed=0;
            temp2= temp[i];//字符转ascii数字
            temp3 = temp[0];
            if (temp.size() >= 20) { cout << "Wrong"<<endl; break; }//字符多于20break
            if(temp3<65 || temp3> 90)
                if (temp3 < 97 || temp3> 122) 
                { cout << "Wrong"<<endl; break; }//开头不是大小写字母就break
            if (48 <= temp2 && temp2 <= 57) { shuzi_num += 1; }
            if ((65 <= temp2 && temp2 <= 90 )|| (97 <= temp2 && temp2 <= 122)) { zimu_num += 1; }
            //if (i == 0)continue;//第一次循环不需要走下去不然bug
            if (temp2 < 48 || temp2 > 57)//判断是不是数字
                if (temp2 < 65 || temp2> 90)
                    if (temp2 < 97 || temp2> 122)//判断是不是字母
                    {
                        cout << "Wrong"<<endl; break;//第二项往后开始不是字母数字就break
                    }
            //往下只能是i=1之后和数字大小写字母
            if (48 <= temp2&& temp2 <= 57)shuzi_num+=1;//记录有几个数字
            if ((65 <= temp2&& temp2 <= 90) || (97 <= temp2&&temp2 <= 122))zimu_num += 1;//记录有几个字母
            if(i== temp.size()-1)
                if (shuzi_num == 0 || zimu_num == 0) { cout << "Wrong"<<endl;  break; }//用户名需要包含至少一个字母和一个数字
            succeed = 1;
        }
        if (succeed == 0)continue;
        if (succeed == 1)cout << "Accept"<<endl;
    }
    return 0;
}
  • 写回答

2条回答 默认 最新

  • _GX_ 2022-09-23 07:05
    关注
    #include <iostream>
    #include <string>
    
    int main()
    {
        int T;
        std::string username;
        std::cin >> T >> std::ws;
        for (int i = 0; i < T; i++)
        {
            std::getline(std::cin, username);
            bool valid = true;
            int num_letters = 0, num_digits = 0;
            for (std::size_t i = 0; i < username.size(); i++)
            {
                if (i == 0 && !std::isalpha(username[i]))
                {
                    valid = false;
                    break;
                }
                if (std::isalpha(username[i]))
                    num_letters++;
                else if (std::isdigit(username[i]))
                    num_digits++;
                else
                {
                    valid = false;
                    break;
                }
            }
            if (num_letters == 0 || num_digits == 0)
                valid = false;
            std::cout << (valid ? "Accept" : "Wrong") << '\n';
        }
        return 0;
    }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 9月23日

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作