题目大意:给出了两个连分数,比较一下哪个大、哪个小。
题目分析:我觉得这道题不错,就整理过来啦。
原题链接:https://biancheng.love/contest/40/problem/C/index
代码如下:
# include<iostream> # include<cstdio> # include<cmath> # include<string> # include<vector> # include<list> # include<set> # include<map> # include<queue> # include<cstring> # include<algorithm> using namespace std; # define LL long long # define REP(i,s,n) for(int i=s;i<n;++i) # define CL(a,b) memset(a,b,sizeof(a)) # define CLL(a,b,n) fill(a,a+n,b) const double inf=1e30; const int INF=1<<30; const int N=100005; int n,m; int a[N],b[N]; int f(int id) { if(a[id]>b[id]) return 1; if(a[id]<b[id]) return -1; if(id==n&&id==m) return 0; if(id==n) return -1; if(id==m) return 1; int k=f(id+1); if(k>0) return -1; else if(k<0) return 1; return 0; } int main() { while(scanf("%d",&n)!=EOF) { REP(i,0,n+1) scanf("%d",a+i); scanf("%d",&m); REP(i,0,m+1) scanf("%d",b+i); int k=f(0); if(k==0) printf("= "); else if(k>0) printf("> "); else printf("< "); } return 0; }