• Source
    1. #include <iostream>
    2. #include <vector>
    3. using namespace std;
    4.  
    5. int ucln (int a, int b)
    6. {
    7. while (b!=0)
    8. {
    9. int r=a%b;
    10. a=b;
    11. b=r;
    12. }
    13. return a;
    14. }
    15.  
    16. int main ()
    17. {
    18. int n, m;
    19. cin>>n>>m;
    20. vector <int> P; //P[]={};
    21. vector <int> Q; //Q[]={};
    22. int hs;
    23. for (int i=0; i<=n; i++)
    24. {
    25. cin>>hs;
    26. P.push_back(hs);
    27. }
    28. for (int i=0; i<=m; i++)
    29. {
    30. cin>>hs;
    31. Q.push_back(hs);
    32. }
    33. if (n>m)
    34. {
    35. if (P[0]*Q[0]>0) cout<<"Infinity";
    36. else cout<<"-Infinity";
    37. }
    38. else if (n<m)
    39. {
    40. cout<<"0/1";
    41. }
    42. else
    43. {
    44. int cs=ucln (P[0], Q[0]);
    45. if ((Q[0]<0 && cs>0) || (Q[0]>0 && cs<0))
    46. {
    47. cs=cs*-1;
    48. cout<<(P[0]/cs)<<"/"<<(Q[0]/cs);
    49. }
    50. else
    51. {
    52. cout<<(P[0]/cs)<<"/"<<(Q[0]/cs);
    53. }
    54. }
    55. return 0;
    56. }