1962. Username Validation
Description
A website requests its new user to register a user name before using it. A valid (有效的) username should: (1) Contain only letters (a~z, A~Z) and digits (0~9); (2) have neither less than 6 characters nor more than 10 characters (6 <= name length <= 10); and (3) start with a letter (a~z, A~Z).
Please write a program to check whether a given string is a valid username or not.
Input
A string in a single line, which is the user name. The string doesn't include any spaces, and contains at most 15 letters.
Output
“Valid” or “Invalid”.
Sample Input
Tom_cat
Sample Output
Invalid
// source code of submission 964202, Zhongshan University Online Judge System
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
bool b = true;
string str;
cin >> str;
int len = str.length();
for ( int i = 0;i < len; i++)
{
if ( (str[i]>= 'A' && str[i]<= 'Z') || (str[i]>='a'&&str[i]<='z') || (str[i]>= '0' &&str[i]<= '9') )
;
else b = false;
}
if ( (str[0]>= 'a' && str[0]<= 'z')||(str[0]>='A'&&str[0]<='Z') )
;
else b = false;
if (len < 6 || len > 10)
b = false;
if(b)
cout << "Valid" << endl;
else cout << "Invalid" << endl;
return 0;
}