c++,50分,#3#4WA,问题出在4个if里,求大佬帮忙
查看原帖
c++,50分,#3#4WA,问题出在4个if里,求大佬帮忙
430920
Tis员工楼主2022/4/9 22:05
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int n,t;
int main()
{
    //freopen("cantor.in","r",stdin);freopen("cantor.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++){
    	for(int j=1;j<i*2;j++){
    		t++;
    		if(t==n){
    			if(i%2==0)cout<<j<<"/"<<2*i-j;
    			else cout<<2*i-j<<"/"<<j;return 0;
			}
		}
		for(int j=i*2;j>=1;j--){
			t++;
			if(t==n){
				if(i%2==0)cout<<i*2+1-j<<"/"<<j;
				else cout<<j<<"/"<<i*2+1-j;return 0;
			}
		}
	} 
	return 0;
}

#3的数据:

输入:1999

输出:18/46

我的输出:46/18

2022/4/9 22:05
加载中...