forked from RajkumarSony/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weirdTarminal.cpp
38 lines (35 loc) · 892 Bytes
/
weirdTarminal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin,s);
int ans=0;
istringstream ss(s);
while(ss)
{
string word;
int flag=0;
ss>>word;
if(word=="") break;
for(int i=0;i<word.length();i++)
if(!isalpha(word[i]))
{
if(i!=0){
if(i==word.length()-1){
if(word[i]==','||word[i]=='.'||word[i]==';'||word[i]==':'||word[i]=='?'||word[i]=='!') continue;}
else if(word[i]=='.'&&word[i+1]!='.') {flag++;break;}
else if(word[i]=='-'&&isalpha(word[i+1])) continue;
else {flag++;break;}
}
else
{
flag++;break;
}
}
if(flag==0) {ans++;
//cout<<word<<" "<<word.length()<<endl;
}
}
cout<<floor((ans-1)/2) +1;
}