getline为什么会不好用
  • 板块灌水区
  • 楼主yyyymh
  • 当前回复8
  • 已保存回复8
  • 发布时间2022/11/23 08:47
  • 上次更新2023/10/27 01:52:24
查看原帖
getline为什么会不好用
499746
yyyymh楼主2022/11/23 08:47

本人刚才在写水题,用了一下getline,结果发现程序一运行就结束了,没给我输入的机会

代码:

#include <bits/stdc++.h>
using namespace std;
bool zimu(char a){
	if(a>='a'&&a<='z'||a>='A'&&a<='Z')  return true;
	return false;
}
bool ik(char a){
	return a>='A'&&a<='Z';
}
int n,len,sum;
string s;
int main(){
	cin>>n;
	getline(cin,s);
	len=s.length();
	for(int i=0;i<len;i++){
		if(!zimu(s[i])){
			cout<<sum<<endl;
			sum=0;
		}
		else{
			if(i==0&&ik(s[i])||!zimu(s[i-1])&&ik(s[i])){
				sum++;
			}
		}
	}
	return 0;
}
2022/11/23 08:47
加载中...