【问题标题】:Check if each string in file have only one word检查文件中的每个字符串是否只有一个单词
【发布时间】:2020-03-10 01:06:42
【问题描述】:

输入: [1-st string]狗

[2-nd string]我爱狗

[3-rd string]狗爱我

[第4串]爱

输出: [1-st string]狗

[第二串]爱

我如何在 c++ 中做这样的事情?>不使用 vector.Thx :)

【问题讨论】:

  • 您的问题描述是什么?

标签: c++ arrays string file iostream


【解决方案1】:

您有一个格式为“B 类中没有 A”的问题。此类问题的算法是

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
}

在您的情况下,“类”是“没有空格的字符串”,要检查是否有空格,您只需使用 this condition

【讨论】:

  • 感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2020-03-22
  • 1970-01-01
  • 2021-08-19
  • 1970-01-01
  • 1970-01-01
  • 2012-05-20
  • 1970-01-01
  • 2021-04-04
相关资源
最近更新 更多