招商银行信用卡中心10.10笔试

想请问大家第二题编程怎么做的,我自己觉得没问题了,但是一直无法通过orz
代码如下
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <set>

using namespace std;

int ChangeString(string& a, string& b, int n){
	int res = 0;


	for(int i=0; i<n; i++){
		if(b[i]<a[i]) return -1;
	}

	if(a==b) return 0;

	unordered_map<char, vector<int> > bmp;

	for(int i=0; i<n; i++){
		bmp[b[i]].push_back(i);
	}

	for(auto it=bmp.begin(); it!=bmp.end(); it++){
		char ch = it->first;
		int size = bmp[ch].size();
		int idx = bmp[ch][0];
		int ans = 0;
		set<char> temp;
		if(a[idx]!=ch){
			ans = 1;
        	temp.insert(a[idx]);
        }

		for(int j=1; j<size; j++){
			idx = bmp[ch][j];
			if(a[idx]!=ch && temp.find(a[idx])==temp.end()){
                ans++;
                temp.insert(a[idx]);
            }
		}

		res += ans;
	}

	return res;

}

int main(){
	//freopen("input.txt", "r", stdin);
	int T;
	cin >> T;

	while(T--){
		int n;
		cin >> n;
		string a;
		string b;
		cin >> a >> b;

		int res = ChangeString(a, b, n);
		cout << res << endl;
	}


	return 0;

}


#笔试题目##招商银行信用卡中心#
全部评论
+1,自己能想到的例子都试了一下,结果一提交就是0
点赞 回复 分享
发布于 2020-10-10 21:21
没写出来 +1= =
点赞 回复 分享
发布于 2020-10-10 21:28
我第一题编程都是0我都不懂为啥子😭
点赞 回复 分享
发布于 2020-10-10 21:33
+1,没写出来😭
点赞 回复 分享
发布于 2020-10-10 21:37
+1不知为何一直0%
点赞 回复 分享
发布于 2020-10-10 21:46
+1我也是0,问下对于 aabbcc aackkk 你的算法输出是啥
点赞 回复 分享
发布于 2020-10-11 01:15
我用的java,可能api复杂一点
点赞 回复 分享
发布于 2020-10-11 14:41

相关推荐

不愿透露姓名的神秘牛友
昨天 10:13
已编辑
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务