RE代码求调
查看原帖
RE代码求调
1369010
littlealone楼主2024/12/7 00:11

RE代码求调不知道问题出哪里 样例测试均过了

#include <bits/stdc++.h>
using namespace std;
int main() {
	string A;
	string B;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		cin >> A;
		cin >> B;
		int len1 = A.length();
		int len2 = B.length();
		if (abs(len1 - len2) > 1) {
			cout << "not similar" << endl;
		}
		if (abs(len1 - len2) == 1) {
			if (A.length() > B.length()) {
				for (int i = 0; i < B.length(); i++) {
					if (A.length() == B.length()) {
						cout << A[i] << " " << B[i] << endl;
						if (A[i] != B[i]) cnt++;
						else continue;
					}
					else if (A[i] != B[i]) {
						string temp1=B.substr(0, i - 1);
						string temp2 = B.substr(i + 1, 0);
						B = temp1 + '0' + temp2;
					}
				}
			}
			if (A.length() < B.length()) {
				int len = A.length();
				for (int i = 0; i < B.length(); i++) {
					if (A.length() == B.length()) {
						cout << A[i] << " " << B[i] << endl;
						if (A[i] != B[i]) cnt++;
						else continue;
					}
					else if (A[i] != B[i]) {
						string temp1 = A.substr(0, i - 1);
						string temp2 = A.substr(i + 1, 0);
						A = temp1 + '0' + temp2;
					}
				}
			}
			if (cnt > 1) cout << "not similar" << endl;
			else cout << "similar" << endl;
		}
		if (abs(len1 - len2) == 0) {
			for (int i = 0; i < n; i++) {
				if (A[i] != B[i]) {
					cnt++;
				}
			}
			if (cnt > 1) cout << "not similar" << endl;
			else cout << "similar" << endl;
		}
	}
	return 0;
}
2024/12/7 00:11
加载中...