输出为空,请检查一下你的代码有没有循环输入处理多个case

碰到了两次这种情况,并且在考试状态下,完全不给任何提示,并且说通过率为0,让人很蛋疼,在自己的IDE下任何例子都能通过。

最后找到这道题,提示说是:输出为空,请检查一下你的代码有没有循环输入处理多个case 。查阅资料才发现是牛客要求你的代码能够一次调用之后处理完它给的所有案例。就是所谓的循环处理多个事件。

https://www.nowcoder.com/practice/784efd40ed8e465a84821c8f3970b7b5?tpId=49&&tqId=29297&rp=1&ru=/activity/oj&qru=/ta/2016test/question-ranking

每组数据输入一个字符串,字符串最大长度为100,且只包含字母,不可能为空串,区分大小写。
#include <iostream>
#include <string>
using namespace std;
void deal_char()
{
	/* abcqweracb
	   abcqwer*/
	string line;
	string des;
	 //getline(cin, line);
	while (getline(cin, line)) 
	{
		//if (line.size() == 0)
		//{
		//	return;
		//}
		int len = line.size();
		des.push_back(line[0]);
		//des[0] = line[0];
		int i = 0;
		int j = 0;

		for (i = 1; i < len; ++i)
		{
			for (j = 0; j < des.size(); ++j)
			{
				if (des[j] == line[i])
				{

					break;
				}
				if (j == des.size() - 1)
				{
					des.push_back(line[i]);
				}
			}
		}
		for (auto& s : des)
		{
			cout << s;
		}
        des.clear();
		cout << endl;
	}
}
int main()
{
	 
        deal_char();
	 
	
	system("pause"); 
	return 0;
}

相信通过这个例子对你有所帮助,牛客的傻瓜判题你需要去迎合它。

发布了157 篇原创文章 · 获赞 98 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_43447989/article/details/103019336