Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- int main()
- {
- int q=0;
- char x;
- int s=0;
- ifstream in("text.txt");
- while(in.peek()!=EOF)
- {
- in>>x;
- switch(q)
- {
- case 0: if (x=='_')
- q=1;
- else
- q=0;
- break;
- case 1:
- if (x>='a'&& x<='z')
- q=2;
- else if (x>='0' && x<='9')
- q=3;
- break;
- case 2:
- if (x>='a'&& x<='z')
- q=2;
- else if (x=='_')
- {
- s++;
- q=4;
- }
- else if (x>='0' && x<='9')
- q=0;
- break;
- case 3: if(x>='0' && x<='9')
- q=3;
- else if(x=='_')
- {
- s++;
- q=4;
- }
- else if (x>='a'&& x<='z')
- q=0;
- break;
- case 4:
- if (x>='a'&& x<='z')
- q=2;
- else if (x>='0' && x<='9')
- q=3;
- break;
- }
- }
- cout<<"Количество цифр и слов = "<<s<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement