杭电OJ2024

杭电OJ2024

这题我没注意到中间可以是数字、字母和下划线的组合 浪费半天时间

#include
#include
int main(){
	int n =0;
	char a[100][100];
	while(scanf("%d",&n)!=EOF){
		getchar();
		for(int i = 0;i<n;i++){
			int flag = 1;
			gets(a[i]);
			for(int j = 0;j<strlen(a[i]);j++){
				if(j == 0){
					if((a[i][j] == '_')||(a[i][j]>='a'&&a[i][j]<='z')||(a[i][j]>='A'&&a[i][j]<='Z')){
						continue;
					}else{
						flag = 0;
					    break;
					}
				}else{
					if((a[i][j] == '_')||(a[i][j]>='a'&&a[i][j]<='z')||(a[i][j]>='A'&&a[i][j]<='Z')||(a[i][j]>='0'&&a[i][j]<='9')){
						continue;
					}else{
						flag = 0;
					    break;
					}
				}
				if(a[i][j]==' '){
					flag = 0;
					break;
				}
				
			}
			if(flag == 0){
				printf("no\n");
			}else{
				printf("yes\n");
			}
		}
	}
	return 0;
}

你可能感兴趣的:(杭电OJ,算法,杭电OJ2024)