帮我改一下错误:#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;
}
```