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

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

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


#include
using namespace std;

int main()
{
    //cout << "先输入循环次数再给爷几个数:";
    string temp;
    int temp2,temp3;
    int l;
    start:;
    cin >> l;//题意输入几个名字
    if (!cin) { cout << "Wrong"<1024, '\n');goto start; }
    for (int i = 0; i < l; i++)//题意输入几个名字就循环几次
    {
        cin >> temp;
        if (!cin) { cout << "Wrong"<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"<break; }//字符多于20break
            if(temp3<65 || temp3> 90)
                if (temp3 < 97 || temp3> 122) 
                { cout << "Wrong"<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"<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"<break; }//用户名需要包含至少一个字母和一个数字
            succeed = 1;
        }
        if (succeed == 0)continue;
        if (succeed == 1)cout << "Accept"<0;
}
#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;
}

1.你想判断输入的不是空,应该写if(!l)而不是if(!cin),这纯粹是在瞎写
2.你使用了string 类型需要引用
3.对于temp.size()和temp[0]的判断应该放到循环之前,而不是每次循环都判断
4.一个简单的temp2 的判断你怎么写出5个if来,很多分支都重复了
5.shuzi_num 的清零放在循环之前或者之后即可,不要判断循环到字符串的最后一位清零
而且这个变量本来就是在循环里定义的,根本不需要清零,下次循环又是定义了一个新的变量并且初始化成0了