我不知道如何计算每个句子中有多少单词,这样做的一个例子就是:string sentence = "hello how are you. I am good. that's good."
让它像:
//sentence1: 4 words
//sentence2: 3 words
//sentence3: 2 words
Run Code Online (Sandbox Code Playgroud)
我可以得到句子的数量
public int GetNoOfWords(string s)
{
return s.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
label2.Text = (GetNoOfWords(sentance).ToString());
Run Code Online (Sandbox Code Playgroud)
我可以得到整个字符串中的单词数
public int CountWord (string text)
{
int count = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] != ' ')
{
if ((i + 1) == text.Length)
{
count++;
}
else
{
if(text[i + …Run Code Online (Sandbox Code Playgroud) 我在GlobalGameEnums.h中创建了一个枚举.我在Board.h中包含了这个标题,我已经在我的类中声明了但它不会让我使用枚举值.
GlobalGameEnums.h:
#ifdef GLOBALGAMEENUMS_H
#define GLOBALGAMEENUMS_H
enum class e_Side
{
Right,
Left
};
#endif
Run Code Online (Sandbox Code Playgroud)
而Board.h:
#ifndef BOARD_H
.
.
#include "GlobalGameEnums.h"
class Board
{
public:
Board(int i_boardSize, int i_lowBound, int i_highBound);
~Board();
int MakePlayerMove(enum e_Side i_sideTaken )
{
switch (i_sideTaken)
{
case e_Side::Left:
break;
case e_Side::Right:
break;
}
}
private:
std::vector<Cell> m_cellVector;
};
#endif
Run Code Online (Sandbox Code Playgroud)
在方法MakePlayerMove的声明中,它确实识别e_Side类型,但在方法体中,它给出了使用Left/Right(Error: enum "e_Side" has no member "Left")的错误.
我已经尝试了很多配置并搜索了一个旧的解决方案,但无法使其正常工作.
以下表达式的值是多少?
I = 1;
I = (I<<= 1 % 2)
Run Code Online (Sandbox Code Playgroud)
选择以下内容:
(a) 2
(b) 1
(c) 0
(d) syntax error
Run Code Online (Sandbox Code Playgroud) 我在c ++的banker算法实现项目
但我在资源请求中有一个小错误:')
我不知道是什么错误.第一个if声明不起作用:(
#include<iostream>
#include<vector>
using namespace std;
int main() {
int work[4];
int allocation[5][4];
int max[5][4];
int need[5][4];
int p, pr, r, a, aval[4], req[4];
bool state[5], test;
vector < int > avl;
//----------------------------------------
test = true;
for (int i = 0; i < 4; i++)
work[i] = aval[i];
for (int i = 0; i < 5; i++)
state[i] = false;
//----------------------------enter p r---------------------------------
cout << "Enter the number of processes in the system :";
cin …Run Code Online (Sandbox Code Playgroud) #include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int * add(int *, int *);
int add(int, int);
void main() {
int a, b, sum, *z;
cout << "enter the value of a & b";
cin >> a >> b;
z = add(&a, &b);
sum = add(a, b);
cout << "\nthe sum is: " << sum << endl;
cout << "the sum is :" << *z << endl; getch();
}
//.....calling with value.....
int add(int a, int b) {
int s;
s = a + b; …Run Code Online (Sandbox Code Playgroud)