放寒假了,想找个不错的 平台培养自己的代码能力,选择了牛壳网,今天开始做了第一道题,很是困难,但是相信自己一定会坚持下去的,下面直接上问题并解决。
敲完代码让我明白了几点;一我是真的菜,独立完成感到很困难,二是有时候没比较追求面向对象编程,过程编程往往事半功倍,三是要培养自己代码的鲁棒性,才能通过编译。
具体代码解决如下:
#include<iostream>
#include<string>
using namespace std;
//判断密码中是否至少出现大写字母,小写字母和数字这三种字符类型中的两种;
bool judge(string& s)
{
bool flag1 = false;//用来判断是否出现数字
bool flaga = false;//用来判断是否出现小写字母
bool flagA = false;//用来判断是否出现大写字母
for (int i = 0; i<s.length(); i++)
{
if (s[i]<'9'&&s[i]>'0')
{
flag1 = true;
}
else if (s[i]<'z'&&s[i]>'a')
{
flaga = true;
}
else if (s[i]<'Z'&&s[i]>'A')
flagA = true;
}
if ((flag1&&flaga) || (flag1&&flagA) || (flaga&&flagA))
{
return true;
}
return false;
}
int main()
{
int n;//用来保存用户将要输入的密码次数
string password;//用来存储密码
cout << "请输入你想要输入的密码次数:";
cin >> n;
for (int i = 0; i<n; i++)
{
cin >> password;
if (password[0]<'9'&&password[0]>'0')
{
cout << "NO" << endl;
continue;
}
if (password.length()<8)
{
cout << "NO" << endl;
continue;
}
if (!judge(password))
{
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
}
return 0;
}
不同的判断用于解决不同的问题,我们需要将问题具体化,不能一头雾水。。。