哔哩哔哩后台服务器端笔试--第三题 20%啥情况啊

#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
void splitstring(const string& srcstr, vector<string>& vec, const string& separator)
{
	string::size_type possubstringstart;
	string::size_type posseparator;
	posseparator = srcstr.find(separator);
	possubstringstart = 0;
	while (string::npos != posseparator)
	{
		vec.push_back(srcstr.substr(possubstringstart, posseparator - possubstringstart));
		possubstringstart = posseparator + separator.size();
		posseparator = srcstr.find(separator, possubstringstart);
	}
	if (possubstringstart != srcstr.length())
		vec.push_back(srcstr.substr(possubstringstart));
}
int main()
{
	vector<string> input, input1;
	string tmp;
	map<string, string> mpout;
	getline(cin, tmp, '\n');
	splitstring(tmp, input, " ");
	string tmp1 = input[0];
	string tmp2 = input[1];
	splitstring(input[2], input1, tmp1);
	int len = input1.size();
	cout << len << endl;
	for (int i = 0; i < len; i++)
	{
		//cout << input1[i] << endl;
		vector<string> input2;
		splitstring(input1[i], input2, tmp2);
		mpout.insert(pair<string, string>(input2[0], input2[1]));
	}
	for (map<string, string>::iterator it = mpout.begin(); it != mpout.end(); it++)
	{
		if (!it->first.empty() && !it->second.empty())
		cout << it->first << " " << it->second << endl;
	}
	return 0;
}

#笔试题目##哔哩哔哩#
全部评论
还有 老哥你这代码写的太复杂了吧,看起来太难懂了  这是我的代码 你可以借鉴一下,看看哪里有问题 #include<bits/stdc++.h> using namespace std; #define pii pair<string,string> int main(){   char f,k;   cin>>f>>k;   string s;   cin>>s;   vector<pii>vq;   bool fa = 0 ;   string x,y;   for(int j=0;j<s.size();j++){      if(s[j]==k){         fa = 1;         continue;      }      if(s[j]==f){         fa = 0;         if(x.size()>0&&y.size()>0)           vq.push_back(make_pair(x,y));         x="";         y="";         continue;      }      if(!fa){        x+=s[j];      }else{        y+=s[j];      }   }   if(x.size()>0&&y.size()>0)      vq.push_back(make_pair(x,y));   cout<<vq.size()<<endl;   for(pii p:vq){     cout<<p.first<<" "<<p.second<<endl;   } } /* # : a:dasd3#bsda:asda8 */
点赞 回复 分享
发布于 2019-09-10 22:31
判空 有可能 #c#   ###
点赞 回复 分享
发布于 2019-09-10 21:16
我估计再加个判断 就A了
点赞 回复 分享
发布于 2019-09-10 21:03
同20%,做了40分钟,然后8点有面试,直接提交了
点赞 回复 分享
发布于 2019-09-10 21:03
直接输出测试用例 80%
点赞 回复 分享
发布于 2019-09-10 21:01

相关推荐

哥_留个offer先:跟他说,你这个最好用c#,微软就用c#Java不适合这个项目
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务