4 条评论

  • @ 2024-7-12 14:32:21

    image

    • @ 2024-7-12 14:32:10

      image

      • @ 2024-7-12 11:32:06

        密码合规检测

        #include <iostream>
        using namespace std;
        char line[101];
        char pwd[101];
        // 检查从 str 开始、长度为 l 的密码是否合规
        bool check(char * str, int l) {
        	if (l < 6 || l > 12)
        		return false;
        	bool hasC = false, hasL = false, hasD = false, hasS = false;
        	for (int i = 0; str[i] != '\0'; i++) {
        		if ('A' <= str[i] && str[i] <= 'Z') {
        			hasC = true;
        		} else if ('a' <= str[i] && str[i] <= 'z') {
        			hasL = true;
        		} else if ('0' <= str[i] && str[i] <= '9') {
        			hasD = true;
        		} else if (str[i] == '!' || str[i] == '@' ||
        			str[i] == '#' || str[i] == '$') {
        			hasS = true;
        		} else
        			return false;
        	}
        	if (!hasS)
        		return false;
        	if (hasC + hasL + hasD < 2)
        		return false;
        	return true;
        }
        int main() {
        	cin >> line;
        // 按逗号对输入进行切分,并依次判断
        	int len = 0;
        	for (int i = 0; line[i] != '\0'; i++) {
        		if (line[i] != ',') {
        			pwd[len] = line[i];
        			len++;
        		} else {
        			pwd[len] = '\0';
        			if (check(pwd, len))
        				cout << pwd << endl;
        			len = 0;
        		}
        	}
        	if (len > 0) {
        		pwd[len] = '\0';
        		if (check(pwd, len))
        			cout << pwd << endl;
        	}
        	return 0;
        }
        
        • @ 2024-7-12 11:30:38

          春游

          #include <iostream>
          using namespace std;
          bool arrive[1000];
          int main() {
          	int n = 0, m = 0;
          	cin >> n >> m;
          // 初始化 arrive 数组为所有同学均未报到
          	for (int i = 0; i < n; i++)
          		arrive[i] = false;
          // 依次报到 m 次
          	for (int i = 0; i < m; i++) {
          		int code = 0;
          		cin >> code;
          		arrive[code] = true;
          	}
          // 依次检查 n 位同学是否到达
          	bool all = true;
          	for (int i = 0; i < n; i++) {
          		if (!arrive[i]) {
          			if (all) {
          				cout << i;
          				all = false;
          			} else {
          				cout << " " << i;
          			}
          		}
          	}
          // 处理全部到达的特殊情况
          	if (all)
          		cout << n;
          	cout << endl;
          	return 0;
          }
          
          • 1