HDU2043密码

问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2043

代码:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5. int main()
  6. {
  7. int m,i,k;
  8. int a,b,c,d;
  9. char s[51];
  10. cin>>m;
  11. getchar();
  12. while(m--)
  13. {
  14. a=b=c=d=0;
  15. gets(s);//必须用puts(s)来接收输入的字符串,用scanf("%s",s)不行!
  16. k=strlen(s);
  17. if(k<8 || k>16)
  18. {
  19. cout<<"NO"<<endl;
  20. continue;
  21. }
  22. for(i=0;s[i]!='\0';i++)
  23. {
  24. if(s[i]>='A' && s[i]<='Z') a++;
  25. else if(s[i]>='a' && s[i]<='z') b++;
  26. else if(s[i]>='0' && s[i]<='9') c++;
  27. else if(s[i]=='~'||s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]==36||s[i]=='%'||s[i]=='^')
  28. d++;
  29. }
  30. int k[4]={a,b,c,d};
  31. sort(k,k+4);//将abcd按照升序排序,若k[1]!=0;则密码正确,反之密码错误!
  32. if(k[1]!=0) cout<<"YES"<<endl;
  33. else cout<<"NO"<<endl;
  34. }
  35. return 0;
  36. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员班长

感谢您的一路相伴

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值