HDU ACM 11 2024 C语言合法标识符

#include 
#include 
using namespace std;
int main()
{
    int n, Yi = 0;
    string Lu;
    scanf("%d%*c", &n);
    while (n--)
    {
        getline(cin, Lu);
        int y = Lu.length();
        if ((!isalpha(Lu[0])) && Lu[0] != '_')
        {
            cout << "no" << endl;
            continue;
        }
        else if (isalpha(Lu[0]) || Lu[0] == '_')
        {
            for (int i = 0; i < y; i++)
            {
                if ((Lu[i] >= 'a' && Lu[i] <= 'z') || (Lu[i] >= 'A' && Lu[i] <= 'Z') || Lu[i] == '_' || (Lu[i]>='0' && Lu[i]<='9'))
                        Yi++;
            }
        }
        if ( Yi == y)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
        Yi = 0;
    }
    return 0;
}

你可能感兴趣的:(HDU ACM 11 2024 C语言合法标识符)