提问人:Olafus 提问时间:11/14/2019 更新时间:11/14/2019 访问量:173
检查文件中的每个字符串是否只有一个单词
Check if each string in file have only one word
问:
输入: [第 1 个字符串]狗
[第 2 个字符串]我爱狗
[第 3 个字符串]狗爱我
[第 4 根字符串]爱
输出: [第 1 个字符串]狗
[第 2 个字符串]爱
我怎样才能在 c++ 中做这样的事情?>不使用矢量。谢谢:)
答:
0赞
v010dya
11/14/2019
#1
您有一个格式为“没有 A 属于 B 类”的问题。此类问题的算法是
bool wrong = false;
while ( /* there is another A */ )
{
if ( /* check if it is NOT within a class */ )
{
wrong=true;
break;
}
}
if (wrong)
{
// here you know that at least one thing was NOT within a class B
}
else
{
// here you know that every item A was within a class B
}
在您的例子中,“类”是“没有空格的字符串”,要检查是否有空格,您只需使用此条件。
评论
0赞
Olafus
11/14/2019
谢谢你的帮助
评论