15分求调,玄关
查看原帖
15分求调,玄关
1023774
rui_de_aihao楼主2024/12/2 16:06
#include <iostream>
#include <string>
using namespace std;
int s9(int n,  string s1,  string s2,  string t1,  string t2) {
	int st = 0;
	if (s1 == s2) {
		return n;
	}
	if (t1 == t2) {
		for (int i = 0; i < n; i++) {
			if (s1[i] == s2[i]) st++;
			else if (t1[i] == '1') {
				for (int j = i + 1; j < n; j++) {
					if (t1[j] == '1' && s1[i] == s2[j] && s1[j] == s2[i]) {
						swap(s2[i], s2[j]);
						st++;
						break;
					}
				}
			}
		}
	} else if (s1.find('0') ==  string::npos || s1.find('1') ==  string::npos) {
		char targetChar = s1[0];
		for (int i = 0; i < n; i++) {
			if (t2[i] == '1' && s2[i]!= targetChar) {
				for (int j = i + 1; j < n; j++) {
					if (t2[j] == '1' && s2[j] == targetChar) {
						swap(s2[i], s2[j]);
						break;
					}
				}
			}
			if (s1[i] == s2[i]) st++;
		}
	} else {
		for (int i = 0; i < n; i++) {
			if (s1[i] == s2[i]) st++;
			else if (t1[i] == '1' && t2[i] == '1') {
				for (int j = i + 1; j < n; j++) {
					if (t1[j] == '1' && t2[j] == '1' && s1[i] == s2[j] && s1[j] == s2[i]) {
						swap(s1[i], s1[j]);
						swap(s2[i], s2[j]);
						st++;
						break;
					}
				}
			}
		}
	}
	return st;
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		string s1, s2, t1, t2;
		cin >> n >> s1 >> s2 >> t1 >> t2;
		cout << s9(n, s1, s2, t1, t2) <<  endl;
	}
	return 0;
}

那错了?大佬们求求了 QwQ

2024/12/2 16:06
加载中...