B题求助!

为啥第23行 b[[i]<temp 加个等号写成b[i]<=temp就过了,个人感觉加不加都一样

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define INIT ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int gcd(int a, int b){ return b? gcd(b, (a%b)): a; }
const int N = 300010;

int n,m;
string a,b;

char lx[N]; //lx[]和idx[]这俩个数组记录b串第i个位置的右边(包括第i个位置)最小的值,及其位置
int idx[N]; 

void solve(){

	cin >> n >> a >> b;

	char temp = '9';
	int tempi = n;
	for(int i = n-1; i >=0; --i){    ///从右往左遍历实现
		if(b[i] <= temp){ //写成 if(b[i]<temp) 只过了86.6%
			temp = b[i];
			tempi = i+1;
		}
		lx[i] = temp;
		idx[i] = tempi;
	}
    
	for(int i = 0; i < n; i++){
		if(a[i] > lx[i]) {
			cout << i+1 << ' ' << idx[i] << endl;
			return;
		}
	}
	
    if(a[0] == b[0]) cout << 1 << " " << 1 << endl;
    else cout << 2 << " " << 2 << endl;

}

int main(){
	INIT;
	int _ = 1;
	cin >> _;
	while(_--){
		solve();
	}

}

全部评论
是要加=号的呀
点赞
送花
回复
分享
发布于 2023-02-12 16:06 上海
看不太明白
点赞
送花
回复
分享
发布于 2023-02-12 16:15 香港
秋招专场
校招火热招聘中
官网直投

相关推荐

点赞 评论 收藏
转发
8 收藏 评论
分享
牛客网
牛客企业服务