帮我改一下错误:#include <iostream> #include <string> #include <sstream> #include <algorithm> #include <map> using namespace std; bool wordIF(string ch){ stringstream ss; ss << ch; double d; if (!(ss >> d)) return true; else return false; } int termFrequency(string c, map<string, unsigned>& m){ for (int i = 0; i < c.length(); i++){ if (c[i] == '.' || c[i] == ',' || c[i] == '"') c[i] == ' '; } stringstream ss(c); string ch; ss >> ch; if (wordIF){ transform(ch.begin(), ch.end(), ch.begin(), ::tolower); map<string, unsigned>::iterator it = m.find(ch); if (m.count(ch) == 0) it->second++; else m.insert(map<string, unsigned>::value_type(ch, 1)); } return m.size(); } void alphabetSortedFrequency(map<string, unsigned>& m){ map<string, unsigned>::iterator it; for (it = m.begin(); it != m.end(); it++) cout << it->first << " : " << it->second << endl; } int main() { // 从标准输入获取文本串 std::string content; std::getline(std::cin, content, '\n'); map<string, unsigned> msu; // 要求termFrequency实现分词,去掉标点 // 获取单词存放在map中,记录词频(出现次数) // 最后返回不重复的单词数量 unsigned nWords = termFrequency(content, msu); // 按首字母A-Z排序一行一词输出词频 alphabetSortedFrequency(msu); return 0; }

时间: 2023-06-13 21:02:43 浏览: 55
请请问请问需要请问需要改请问需要改什请问需要改什么请问需要改什么错误请问需要改什么错误呢请问需要改什么错误呢?请问需要改什么错误呢?请请问需要改什么错误呢?请提请问需要改什么错误呢?请提供请问需要改什么错误呢?请提供更请问需要改什么错误呢?请提供更具请问需要改什么错误呢?请提供更具体请问需要改什么错误呢?请提供更具体的请问需要改什么错误呢?请提供更具体的信息请问需要改什么错误呢?请提供更具体的信息。
相关问题

求一个点到另外一个点的最小距离 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<vector> #include<cstring> #include<cstdio> #include<cmath> #include<cstdlib> #include<sstream> #include<string> #include<map> using namespace std; typedef long long ll; int dx[4] = { 0, 0, 1, -1 }; int dy[4] = { 1, -1, 0, 0 }; #define fo(i,l,r) for (int i = l; i <= r; ++i) #define F 10005 int n, m, s, t,x,y,ww; ll D[F],w[F][F],vis[F]; int main() { cin >> n >> m >> s >> t; fo(i, 1, n) fo(j, 1, n) { if (i != j) w[i][j] = 0x3f3f3f3f3f; } fo(i, 0, n)//注意0的初始化 D[i] = 0x3f3f3f3f3f; D[s] = 0;//从源点到i的距离 fo(i, 1, m) { scanf("%d%d%d", &x, &y, &ww); w[x][y] = ww; w[y][x] = ww; } //dijkstra算法 int k = 0; fo(i, 1, n) { k = 0; fo(j, 1, n) if (!vis[j] && D[j] < D[k])//一开始找源点 k = j; vis[k] = 1; fo(j, 1, n) if (!vis[j]&&D[k] + w[k][j] < D[j]) { D[j] = D[k] + w[k][j]; } } cout << D[t] << endl; return 0; }不用任何容器来实现这个代码

以下是不使用任何容器实现求一个点到另外一个点的最小距离的代码: ``` #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> #include<cstdlib> #include<sstream> #include<string> #include<map> using namespace std; typedef long long ll; const int F = 10005; int dx[4] = { 0, 0, 1, -1 }; int dy[4] = { 1, -1, 0, 0 }; int n, m, s, t, x, y, ww; ll D[F], w[F][F], vis[F]; int main() { scanf("%d%d%d%d", &n, &m, &s, &t); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (i != j) { w[i][j] = 0x3f3f3f3f3f; } } } for (int i = 0; i <= n; ++i) { D[i] = 0x3f3f3f3f3f; } D[s] = 0; for (int i = 1; i <= m; ++i) { scanf("%d%d%d", &x, &y, &ww); w[x][y] = ww; w[y][x] = ww; } // dijkstra算法 int k = 0; for (int i = 1; i <= n; ++i) { k = 0; for (int j = 1; j <= n; ++j) { if (!vis[j] && D[j] < D[k]) { k = j; } } vis[k] = 1; for (int j = 1; j <= n; ++j) { if (!vis[j] && D[k] + w[k][j] < D[j]) { D[j] = D[k] + w[k][j]; } } } printf("%lld\n", D[t]); return 0; } ``` 这个代码中没有使用任何STL容器,而是使用了基本数据类型和数组来存储和操作数据。

#include <iostream> #include <vector> #include <algorithm> #include <sstream> using namespace std; bool isValidSet(int a, int b, int c) { return (a == b && b == c) || (a + 1 == b && b + 1 == c); } string checkHu(vector<int>& nums) { int n = nums.size(); if (n % 3 != 2) { return "XIANGGONG"; } sort(nums.begin(), nums.end()); for (int i = 0; i < n - 5; i += 3) { if (!isValidSet(nums[i], nums[i + 1], nums[i + 2])) { return "BUHU"; } } if (nums[n - 2] != nums[n - 1]) { return "BUHU"; } return "HU"; } int main() { vector<int> nums; string line; string result; while (true) { getline(cin, line); if (line == "0") { break; } stringstream ss(line); int num; while (ss >> num) { nums.push_back(num); } result = checkHu(nums); cout << result << endl; nums.clear(); } return 0; }如何加以定义个数字的数量不超过4个,集合中元素的数量不超过14个

可以在读入每一行的数字后,统计每个数字出现的次数,如果有任何一个数字的出现次数超过了4次,直接返回"BUHU";同时,如果集合中元素的数量超过了14个,也直接返回"BUHU"。代码如下: ``` #include <iostream> #include <vector> #include <algorithm> #include <sstream> #include <unordered_map> // 添加头文件以使用 unordered_map using namespace std; bool isValidSet(int a, int b, int c) { return (a == b && b == c) || (a + 1 == b && b + 1 == c); } string checkHu(vector<int>& nums) { int n = nums.size(); if (n % 3 != 2) { return "XIANGGONG"; } // 使用 unordered_map 统计数字出现次数 unordered_map<int, int> count; for (int num : nums) { count[num]++; if (count[num] > 4) { return "BUHU"; } } if (count.size() > 14) { // 判断集合中元素数量是否超过14个 return "BUHU"; } sort(nums.begin(), nums.end()); for (int i = 0; i < n - 5; i += 3) { if (!isValidSet(nums[i], nums[i + 1], nums[i + 2])) { return "BUHU"; } } if (nums[n - 2] != nums[n - 1]) { return "BUHU"; } return "HU"; } int main() { vector<int> nums; string line; string result; while (true) { getline(cin, line); if (line == "0") { break; } stringstream ss(line); int num; while (ss >> num) { nums.push_back(num); } result = checkHu(nums); cout << result << endl; nums.clear(); } return 0; } ```

相关推荐

#include <stdio.h> #include <stdlib.h> #include <string.h> #include #include <sys/time.h> #include <unistd.h> #include #include <signal.h> #include #include <algorithm> #include <iostream> #include <map> #include <string> #include <queue> #include <vector> #include <sstream> #define LOG_BRASERO_NUM 15 using namespace std; static char *g_cpBrasero[] = { (char *) "ID", (char *) "刻录时间", (char *) "刻录机型号", (char *) "光盘属性", (char *) "刻录状态", (char *) "计算机帐户", (char *) "文件名称", (char *) "文件大小", (char *) "文件类型", (char *) "测试1", (char *) "测试2", (char *) "测试3", (char *) "测试4", (char *) "测试5", (char *) "测试6", }; typedef struct _tagBraseroLog { char cpValue[1024]; } BRASEROLOG; int uosaarch_line_parse(char *pBuffer) { int index, len,lastLen; int ret = 0; char *begin = NULL; char *end = NULL; char *lastEnd = NULL; //debug printf("进入了扫描"); BRASEROLOG BraseroLog[LOG_BRASERO_NUM]; memset(&BraseroLog, 0, LOG_BRASERO_NUM * sizeof(BRASEROLOG)); for (index = 0; index < LOG_BRASERO_NUM; index++) { begin = strstr(pBuffer, g_cpBrasero[index]); if(NULL == begin) continue; begin=strstr(begin,"="); end = strstr(pBuffer, g_cpBrasero[index + 1]); //end--; if (begin != NULL) { len = strlen("="); unsigned long strSize = end - begin - len ; printf("BraseroLOg[%d]=%s\n",index,BraseroLog[index].cpValue); //strncpy(BraseroLog[index].cpValue, begin + len, std::min(strSize, sizeof(BraseroLog[index].cpValue) - 1)); // printf("PrintLog[%d] = %s\n",index,BraseroLog[index].cpValue); } return 0; } return 1; } int main(){ char a[500] = "ID=1689309873, 刻录时间=2023-07-14 12:44:34, 刻录机型号=TSSTcorp-CDDVDW-SE-218CB-R95M6YMDA00008, 光盘属性=DVD+R, 刻录状态=成功, 计算机帐户=hba, 文件名称=/home/hba/Desktop/刻录测试文件.txt, 文件大小=66 B, 文件类型=文档"; uosaarch_line_parse(a); return 0; }

最新推荐

recommend-type

grpcio-1.63.0-cp38-cp38-linux_armv7l.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

SQLyog-13.1.3-0.x86Community.exe

SQLyog-13.1.3-0.x86Community
recommend-type

VB自动出题题库系统设计(源代码+系统).rar

计算机专业毕业设计VB精品论文资源
recommend-type

debugpy-1.0.0b2-cp35-cp35m-manylinux1_i686.whl

Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

实战自学python如何成为大佬(目录):https://blog.csdn.net/weixin-67859959/artic

实战自学python如何成为大佬(目录):https://blog.csdn.net/weixin-67859959/artic
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

用Spring boot和vue写一个登录注册界面

好的,这是一个比较常见的技术问题,我可以为您提供一些参考资料和思路。首先,您可以使用Spring Boot作为后端框架来处理用户认证和注册的逻辑,比如使用Spring Security实现用户登录认证。同时,您还需要设计相应的数据模型和数据库表结构来存储用户信息。在前端方面,您可以使用Vue.js作为框架来构建登录注册页面,使用Axios来发起API请求并和后端进行交互。当然,在实现过程中,还需要考虑一些具体细节,比如数据校验、安全性和用户体验等方面。希望这些信息能够帮助到您。
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。