雷普问题求助
查看原帖
雷普问题求助
47911
xiaozhangma楼主2023/5/10 23:02

本人原本在愉快的切水题,结果RE->WA,跟雷普的是,我认为三种完全等价的写法两种会RE,一种会WA()代码如下:

/*
		F(i, 0, st.size() - 1){
			if(st[i] == ' '){
				a[ ++ cnt] = now;
				now = 0;
			}else{
				now = now * 10 + st[i] - '0';
			}
		}这样写会RE 
		
		for(int i = 0 ; i <= st.size() - 1; i ++ ){
			if(st[i] == ' '){
				a[ ++ cnt] = now;
				now = 0;
			}else{
				now = now * 10 + st[i] - '0';
			}
		}这样也会 
		*/ 
		for(int i = 0 ; i < st.size(); i ++ ){
			if(st[i] == ' '){
				a[ ++ cnt] = now;
				now = 0;
			}else{
				now = now * 10 + st[i] - '0';
			}
		}

总之就是非常离谱,另外,原题并不难,希望大佬能帮忙找出错因,感激不尽! 代码如下:

//code by xiaozhangma
#include<bits/stdc++.h>
#define LL long long
#define F(x,s,t) for(int x=s;x<=t;x++)
using namespace std;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(int x){
	if(x < 0)putchar('-'),x = -x;
	if(x > 9)write(x / 10);
	putchar(x % 10 + '0');
}
const int N = 1e5 + 10;
int n, now, cnt;
int a[N];
int main(){
	n = read();
	
	while(n -- ){
		string st;
		getline(cin, st);
		for(int i = 0 ; i < st.size(); i ++ ){
			if(st[i] == ' '){
				a[ ++ cnt] = now;
				now = 0;
			}else{
				now = now * 10 + st[i] - '0';
			}
		}
		
		a[ ++ cnt] = now;
		now = 0;
	}
	
	sort(a + 1, a + cnt + 1);
	int ans1, ans2;
	F(i, 1, cnt){
		if(a[i] != a[i - 1] + 1){
			if(a[i] != a[i - 1]){
				ans1 = a[i] - 1;
			}else{
				ans2 = a[i];
			}
		}
	}
	printf("%d %d\n",ans1,ans2);
	return 0;
}

2023/5/10 23:02
加载中...