2021.4.11 字节跳动实习笔试题—服务部署
作者:互联网
2021.4.11 字节跳动实习笔试题—服务部署
题目要求
输入输出
代码
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
class Solution {
public:
int demand(string s, string m, int i, int j) {
vector<int> ans;//去重组合
int cnt = 1;
for (int p = 0; p < i; p++) {
ans.push_back(s[p]);
}
for (int q = 0; q < j; q++) {
ans.push_back(m[q]);
}
sort(ans.begin(), ans.end());
for (int n = 0; n < ans.size() - 1; n++) {
if (ans[n] != ans[n + 1])
cnt++;
}
return cnt;
}
vector<int> serve(string s, string m,int t,vector<int> i, vector<int> j) {
vector<int> res ;
for (int a = 0; a < t; a++) {
int tmp=demand(s,m,i[a],j[a]);
res.push_back(tmp);
}
return res;
}
};
int main()
{
Solution s;
string str1, str2;
while (cin >> str1 >> str2) { //
int t;
cin >> t;
vector<int> i1 ;
vector<int> j1 ;
for (int i = 0; i < t; i++) {
int n1,n2;
cin >> n1>>n2;
i1.push_back(n1);
j1.push_back(n2);
}
for (auto x : s.serve(str1, str2, t, i1, j1))
cout << x << endl;
}
}
测试结果
标签:11,2021.4,int,back,++,vector,ans,string,字节 来源: https://blog.csdn.net/baidu_40383992/article/details/116421264