0
点赞
收藏
分享

微信扫一扫

getline使用

戴老师成长记录仪 2022-04-05 阅读 60
算法

getline可以读入整行,以回车作为结尾,故如果输入形式是一个整数n,之后n行含有空格的串,要先进行getline(cin,s);读取完整数n后的空格。

头文件是sstream,string

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
map<string,int>m;
int main()
{
	getline(cin,s);
	string str;
	stringstream newcin(s); 
	//以空格为分隔,隔出每个string
	while (newcin>>str){
		m[str]++;
	}
	cout<<m.size();
	return 0;
}

举报

相关推荐

0 条评论