Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
int isSorted(string st, int n)
{
if (n == 1)
{
return 1;
}
for (int i = 0; i < n - 1; i++)
{
if (st[i] > st[i + 1])
{
return 0;
}
}
return 1;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
string temps1 = s1, temps2 = s2;
int flag = 1;
for(int i = 0; i < n - 1; i++) {
if(s1[i] > s1[i + 1]) {
swap(temps1[i], temps2[i]);
if(isSorted(temps1, n) || isSorted(temps2, n)) {
cout << "Yes" << endl;
flag = 0;
break;
}
}
}
temps1 = s1, temps2 = s2;
for(int i = 0; i < n - 1; i++) {
if(s2[i] > s2[i + 1]) {
swap(temps2[i], temps1[i]);
if(isSorted(temps2, n) || isSorted(temps1, n)) {
cout << "Yes" << endl;
flag = 0;
break;
}
}
}
if(flag) {
cout << "No" << endl;
}
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1117 String Sorted
- Contest
- LU IUJPC : Sylhet Division 2024, Mock Round
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-12-07 11:14:48
- Judged At
- 2024-12-07 11:14:48
- Judged By
- Score
- 1
- Total Time
- 20ms
- Peak Memory
- 800.0 KiB