结构-01. 有理数比较(10)

本题要求编写程序,比较两个有理数的大小。

输入格式:

输入在一行中按照“a1/b1 a2/b2”的格式给出两个分数形式的有理数,其中分子和分母全是整形范围内的正整数。

输出格式:

在一行中按照“a1/b1 关系符 a2/b2”的格式输出两个有理数的关系。其中“>”表示“大于”,“<”表示“小于”,“=”表示“等于”。

输入样例1:

1/2 3/4

输出样例1:

1/2 < 3/4

输入样例2:

6/8 3/4

输出样例2:

6/8 = 3/4
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>


using namespace::std; 

int main(){
  
   
    char s[500001];
    gets(s);
    //划分
    char *p,*q;
    p=strtok(s," "); 
    q=strtok(NULL," ");
    int a,b,c,d;
    sscanf(p,"%d/%d",&a,&b);
    sscanf(q,"%d/%d",&c,&d);
    double m=a/(double)b;
    double n=c/(double)d;
    if(m>n)
    {
        printf("%d/%d > %d/%d",a,b,c,d);
    }else if(m==n)
    {
        printf("%d/%d = %d/%d",a,b,c,d);
    } else
    {
        printf("%d/%d < %d/%d",a,b,c,d);    
    }
      return 0;
}

 

posted @ 2015-02-13 22:34  Joilee  阅读(803)  评论(0编辑  收藏  举报