第一题 实在没有思路,直接 cout << 3; 骗了18%
第二题逐个遍历,在输入上花的时间比较多一点,最后还是AC了,以下是我第二题的代码,求大佬分享一下第一题的代码
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
string s;
vector<string> res;
while (cin >> s) {
res.push_back(s);
if (cin.get() == '\0')
break;
}
int len = res.size();
for (int i = 0; i < len; i++) {
int num = res[i].size();
string tem = res[i];
int flag = 0;
int flag1 = 0;
int flag2 = 0;
int flag3 = 0;
if (num >= 8) {
for (int j = 0; j < num; j++) {
if ((tem[j] >= 'a') && (tem[j] <= 'z') ){
flag++;
continue;
}
else if ((tem[j] >= 'A') && (tem[j] <= 'Z')) {
flag1++;
continue;
}
else if ((tem[j] >= '0') && (tem[j] <= '9')) {
flag2++;
continue;
}
else {
flag3++;
continue;
}
if ((flag > 0 )&& (flag1 > 0 )&& (flag2 > 0 )&& (flag3 > 0)) {
cout << "Ok" << '\n';
break;
}
}
if ((flag > 0 )&& (flag1 > 0) && (flag2 > 0 )&& ( flag3 > 0))
cout << "Ok" << '\n';
else
cout << "Irregular password" << '\n';
}
else
cout << "Irregular password" << '\n';
}
return 0;
}
全部评论
(4) 回帖