c++用cin.getline()并指定EOF结束符可以读入回车换行
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
bool check(char c)
{
if(c == 39 || 48 <= c && c <= 57 ||
65 <= c && c <= 90 || 97 <= c && c <= 122)
return true;
return false;
}
int main()
{
freopen("in.txt","r",stdin);//重定向文件输入
char str[100005];
cin.getline(str,1000005,EOF);//指定EOF或-1为读数据结束标志
// while(cin.getline(str,1000005)) //没有指定结束标志还会读入回车就结束
// {
// cout<<"str:"<<str<<endl;
// }
cout<<"str:"<<str<<endl;
bool flag = false;
int ans = 0;
for(int i = 0; i < strlen(str); i++)
{
if(flag){
if(check(str[i])) continue;
flag = false;
ans++;
} else {
if(!check(str[i])) continue;
flag = true;
}
}
if(flag) ans++;
cout<<ans<<endl;
return 0;
}