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:15 香港
是要加=号的呀
点赞 回复 分享
发布于 2023-02-12 16:06 上海

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
8
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务