社区讨论

求求了!!!

B3843[GESP202306 三级] 密码合规参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mjbhcznn
此快照首次捕获于
2025/12/18 21:32
2 个月前
此快照最后确认于
2025/12/20 21:00
2 个月前
查看原帖
大家快帮我看看
我的代码一直是第1、2、8项测试点WA
求求了,(都给我搞自闭了)
C
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#ifndef bool
#define bool int
#define true 1
#define false 0
#endif

int main() {
	int c;
	while (true) {
		char str[105] = {0};
		int k = 0;
		while (true) {
			c = getchar();
			if (c == EOF) {
				return 0;
			}
			if (k >= 104) {
				break;
			}
			if (c == ',' || c == '\n') {
				break;
			}
			else {
				str[k++] = (char)c;
			}
		}
		str[k] = '\0';
		
		bool isValid = true;
		bool hasUpper = false;
		bool hasLittle = false;
		bool hasDigit = false;
		bool hasSpecial = false;
		
		int length = strlen(str); 
		if (length == 0 || length < 6 || length > 12) {
			isValid = false;
		} else {
			for (int i = 0; i < length; i++) {
				char ch = str[i];
				if ('A' <= ch && ch <= 'Z') {
					hasUpper = true;
				}
				else if ('a' <= ch && ch <= 'z') {
					hasLittle = true;
				}
				else if ('0' <= ch && ch <= '9') {
					hasDigit = true;
				}
				else if (ch == '!' || ch == '@' ||
						ch == '#' || ch == '$') {
					hasSpecial = true;
				}
				else {
					isValid = false;
					break;
				}
			}
			if (isValid) {
				int cnt = 0;
				cnt += (hasUpper ? 1 : 0);
				cnt += (hasLittle ? 1 : 0);
				cnt += (hasDigit ? 1 : 0);
				if (cnt < 2 || !hasSpecial) {
					isValid = false;
				}
			}
		}
		if (isValid) {
			printf("%s\n", str);
		}
		
		if (c == '\n') {
			break;
		}
	}
	
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...