11,“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
string str = Console.ReadLine(); bool isHui = true; for (int i = 0; i < str.Length / 2; i++) { //i str.length-1-i; if (str[i] != str[str.Length - 1 - i]) { isHui = false; break; } } if (isHui) { Console.WriteLine("是回文串"); } else { Console.WriteLine("不是回文串"); }
12,一般来说一个比较安全的密码至少应该满足下面两个条件:
(1).密码长度大于等于8,且不要超过16。
(2).密码中的字符应该来自下面“字符类别”中四组中的至少三组。
这四个字符类别分别为:
1.大写字母:A,B,C...Z;
2.小写字母:a,b,c...z;
3.数字:0,1,2...9;
4.特殊符号:~,!,@,#,$,%,^;
给你一个密码,你的任务就是判断它是不是一个安全的密码。
string str = Console.ReadLine(); if (str.Length >= 8 && str.Length <= 16) { bool isHaveUpper = false; bool isHaveLower = false; bool isHaveNumber = false; bool isHaveSpecial = false; for (int i = 0; i < str.Length; i++) { if (str[i] >= 'A' && str[i] <= 'Z') { isHaveUpper = true; } if (str[i] >= 'a' && str[i] <= 'z') { isHaveLower = true; } if (str[i] >= '0' && str[i] <= '9') { isHaveNumber = true; } //~,!,@,#,$,%,^; if (str[i] == '~' || str[i] == '!' || str[i] == '@' || str[i] == '#' || str[i] == '$' || str[i] == '%' || str[i] == '^') { isHaveSpecial = true; } } int count = 0; if (isHaveUpper) count++; if (isHaveLower) count++; if (isHaveSpecial) count++; if (isHaveNumber) count++; if (count >= 3) { Console.WriteLine("这个是安全密码"); } else { Console.WriteLine("这个密码不安全"); } } else { Console.WriteLine("这个密码不安全 长度不符合规则"); } Console.ReadKey();