问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2043
代码:
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- int main()
- {
- int m,i,k;
- int a,b,c,d;
- char s[51];
- cin>>m;
- getchar();
- while(m--)
- {
- a=b=c=d=0;
- gets(s);//必须用puts(s)来接收输入的字符串,用scanf("%s",s)不行!
- k=strlen(s);
- if(k<8 || k>16)
- {
- cout<<"NO"<<endl;
- continue;
- }
- for(i=0;s[i]!=' ';i++)
- {
- if(s[i]>='A' && s[i]<='Z') a++;
- else if(s[i]>='a' && s[i]<='z') b++;
- else if(s[i]>='0' && s[i]<='9') c++;
- else if(s[i]=='~'||s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]==36||s[i]=='%'||s[i]=='^')
- d++;
- }
- int k[4]={a,b,c,d};
- sort(k,k+4);//将abcd按照升序排序,若k[1]!=0;则密码正确,反之密码错误!
- if(k[1]!=0) cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- return 0;
- }