大厂笔试题
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
695 B

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. string str;
  5. int YinWen_num = 0, KongGe_num = 0, ShuZi_num = 0, Others_num = 0;
  6. cout<<"please input str:"<<endl;
  7. getline(cin, str);
  8. for(int i = 0; i < str.length(); i++){
  9. if((str[i] - 'a' >= 0 && str[i] - 'z' <= 0) || (str[i] - 'A' >= 0 && str[i] - 'Z' <= 0))YinWen_num++;
  10. else if(str[i] - '0' >= 0 && str[i] - '9' <= 0)ShuZi_num++;
  11. else if(str[i] == ' ')KongGe_num++;
  12. else Others_num++;
  13. }
  14. cout<<"YinWen_num is:"<<YinWen_num<<endl;
  15. cout<<"KongGe_num is:"<<KongGe_num<<endl;
  16. cout<<"ShuZi_num is:"<<ShuZi_num<<endl;
  17. cout<<"Others_num is:"<<Others_num<<endl;
  18. return 0;
  19. }