【发布时间】:2016-03-31 16:24:55
【问题描述】:
我正在用 c++ 编写一个程序,它接收字母并将它们打印出来。所以,类似:
AAAAAA
BBBBBB
CCCCCC
我使用 for 循环遍历输入中的所有字母,使用 substr 提取每个字母,然后计算出该字母。 现在,我需要计算第一个垂直位置(粗体字母)有多少个 A,在这种情况下是一个,并计算垂直列中 A 的百分比。 我怎么做?我很困惑,感谢任何帮助!
谢谢!
这是代码:
while(s < numberL)
{
sp = word;
s++
for (int i = 0; i < correct.length(); i++)
{
if(answer.at(i) == correct.at(i))
{
word = answer.substr(i,1);
cout << word;
}
if ( answer.at(i) != correct.at(i) && answer.at(i) != '?')
{
word = answer.substr(i,1);
cout << word;
}
if (answer.at(i) == '?')
{
word = answer.substr(i,1);
cout << word;
}
}
}
【问题讨论】:
-
请向我们展示您尝试过的代码。
-
虽然您已经获得了informed 徽章,但我非常怀疑您阅读了The Tour(尤其是获取实用、详细问题的答案部分)和Help Pages彻底。
-
对不起。我刚刚添加了代码!
-
@samar 你用一些代码编辑了你的问题。下一步是将其设为minimal reproducible example。