-
题目大意
统计一个句子里每个出现的单词的个数 -
思路
-
code
#include<bits/stdc++.h>
using namespace std;
string s;
map<string,int> p;
int main()
{
getline(cin,s);
for(int i=0;i<s.length();i++)
if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]+32;
string ss;
for(int i=0;i<s.length();)
{
while(s[i]==',' || s[i]=='.' || s[i]==' ') i++;
ss.clear();
while(s[i]<='z'&&s[i]>='a') ss.push_back(s[i]),i++;
if(ss.length()>0) p[ss]++;
}
for(auto [u,v]:p) cout<<u<<":"<<v<<endl; //遍历map
return 0;
}
几个函数:
isalpha(s[i]) 判断是不是字母
tolower(s[j]) 转换成小写字母
-
题目大意
-
思路
-
code
这些题目不好,从新找找合适的题目来做,所以没有写更多题了。