列表

详情


NC248195. 再交换

描述

给定两个 n 位的正整数 A,B 满足 ,你必须进行以下操作恰好一次,使得操作后


输出任一组符合要求的 i,j,在本题所给数据范围保证一定有解。

输入描述

每一个测试点包含多组测试数据,第一行输入一个正整数 ,表示该测试点测试数据的数量。

对于每组测试数据:

第一行输入一个正整数

第二行输入一个 n 位正整数

第三行输入一个 n 位正整数

对于每个测试点的多组测试数据,保证

输出描述

对于每组测试数据,一行输出两个正整数 i,j,以空格相隔,表示答案。若有多组解,输出任一组即可。

示例1

输入:

2
3
156
123
3
111
110

输出:

2 1
3 3

说明:

对于第一组测试数据,交换后 A=116, B=523,对于第二组测试数据,交换后 A=110,B=111

原站题解

import java.util.Scanner;
public class Main {
public static void main(String[] arg) {
Scanner scanner = new Scanner(System.in);
// todo
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

C++(clang++ 11.0.1) 解法, 执行用时: 148ms, 内存消耗: 956K, 提交时间: 2023-02-11 18:27:12

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
string a,b;
int n;
cin>>n>>a>>b;
if(a<b) {
if(a[0]!=b[0]) cout<<2<<" "<<2<<endl;
else cout<<1<<" "<<1<<endl;
}
else{
for(int i=0;i<n;i++){
if(a[i]!=b[i]) {
cout<<i+1<<" "<<i+1<<endl;
break;
}
}
}
}
}

pypy3 解法, 执行用时: 692ms, 内存消耗: 28080K, 提交时间: 2023-02-19 19:00:14

for _ in range(int(input())):
n = int(input())
l1 = input()
l2 = input()
if l1 < l2:
print('1 1' if l1[0] == l2[0] else '2 2')
else:
for i in range(n):
if l1[i] != l2[i]:
print(i+1, i+1)
break

Python3 解法, 执行用时: 1366ms, 内存消耗: 5708K, 提交时间: 2023-02-10 21:23:28

t=input()
t=int(t)
while t>0:
n=input()
n=int(n)
a=input()
b=input()
for i in range(n):
c=a[:i]+b[i]+a[i+1:]
d=b[:i]+a[i]+b[i+1:]
if c<d:
print(i+1,i+1)
break
t=t-1

上一题