首页 > 试题广场 >

单词识别

[编程题]单词识别
  • 热度指数:15190 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
输入一个英文句子,把句子中的单词(不区分大小写)按出现次数按从多到少把单词和次数在屏幕上输出来,次数一样的按照单词小写的字典序排序输出,要求能识别英文单词和句号

输入描述:
输入为一行,由若干个单词和句号组成


输出描述:
输出格式参见样例。
示例1

输入

A blockhouse is a small castle that has four openings through which to shoot.

输出

a:2
blockhouse:1
castle:1
four:1
has:1
is:1
openings:1
shoot:1
small:1
that:1
through:1
to:1
which:1
头像 Vibia
发表于 2022-02-22 11:38:25
思路是先截取单词,通过map记录单词个数,再转存vector进行排序。 ">using namespace std; typedef pair<string,int> Word; bool cmp(Word w1,Word w2) { return w1.second>w2 展开全文
头像 KissKernel
发表于 2022-10-01 12:21:42
思路:使用两次map进行计数和排序,第一次map用来统计不同的单词出现的次数。注意最后一个单词要把'.'去掉,大写的字母要转换成小写的字母。第二次的multimap用来将单词出现的次数按照降序排列,因为出现次数可能会有重复的所以这里使用multimap。同时降序排序需要回传一个仿函数 展开全文
头像 牛客287839427号
发表于 2022-12-19 22:13:11
#include<iostream> using namespace std; #include<vector> #include<map> #include<algorithm> int main() { string str; ge 展开全文
头像 牛客447552449号
发表于 2024-01-21 10:52:25
#include <algorithm>//先把单词给分解出来 #include <functional>//转换大小写 #include<iostream>//放入map里面,有这个元素就次数+1,没有就插入 #include <map> #incl 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-15 09:44:46
#include <iostream> #include <map> #include <set> #include <vector> using namespace std; int main(){ set<string> st; 展开全文
头像 普罗列塔丽亚
发表于 2022-02-05 15:51:33
使用双指针截取字符串 #include<iostream> #include<string> #include<map> #include<algorithm> using namespace std; int&nb 展开全文
头像 牛客537392665号
发表于 2024-03-25 10:36:16
#include <stdio.h> #include <stdlib.h> #include <string.h> int panduan(char buchongfu[1000][20],int k,char danci[20]){ int i=0; 展开全文
头像 希望被捞的香菇很想去广西嗦粉
发表于 2023-03-16 19:33:09
#include <iostream> #include <string> #include <map> using namespace std; int main() { //读入字符串 char buf[1000]; fge 展开全文
头像 无问西东gmy
发表于 2023-01-17 20:49:07
#include <iostream> #include <cstring> using namespace std; int main() { char ch[1000][100]; int n; 展开全文
头像 学习的志烜
发表于 2023-10-30 12:46:46
#include <iostream> #include<string> #include<map> using namespace std; int main() { map<string,int>mp; string s; while(ci 展开全文