gpt4 book ai didi

C++基本字符串输入输出

转载 作者:行者123 更新时间:2023-11-28 03:08:57 24 4
gpt4 key购买 nike

好的,我有一个简单的在线编程作业,该作业已通过自动评分工具进行检查。大多数都非常简单,但我无法完成这项任务。这是提示和我的代码。我有一种感觉,我错过了一些相当简单的东西。感谢您的帮助。

Students just took a short, two question, multiple choice quiz. Both questions needed to >be answered correctly to receive credit. As their grader, you must determine whether >students got credit or not. The correct answers were A and D.

Input

The students' answers, sepated by a space.

Output

"Credit" or "No credit"

Example

Input:A C

Output:No credit


我的代码:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string input;
cin >> input;
if (input == "A D")
{
cout << "Credit";
}
else
{
cout << "No credit";
}

return 0;
}

最佳答案

std::cin 将在遇到新行 \n 或空格时停止搜索输入。为了获得整行输入,使用std::getline:

std::string input;
std::getline(std::cin, input);

关于C++基本字符串输入输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18994570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com