zoukankan      html  css  js  c++  java
  • 5C

    Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".

    Input

    each test case contains two numbers A and B. 

    Output

    for each case, if A is equal to B, you should print "YES", or print "NO".

    Sample Input

    1 2
    2 2
    3 3
    4 3

    Sample Output

    NO
    YES
    YES
    NO

    // too young
     1 #include<stdio.h>
     2 int main()
     3 {
     4     int a, b;
     5     while(scanf("%d %d", &a, &b)!=EOF)
     6     {
     7         if(a==b) printf("YES
    ");
     8         else printf("NO
    ");
     9     }
    10     return 0;
    11 }
    Output Limit Exceeded
    // double只能表示15或16位有效数字,而这道题数字可能会十分长
    // 传送门:准确详解:C/C++ float、double数据类型的表示范围及精度
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 int main()
     4 {
     5     double a,b;
     6     char num1[1000000], num2[1000000];
     7     while(scanf("%s %s", num1, num2)!=EOF)
     8     {
     9         a=atof(num1); b=atof(num2);
    10         if(a==b) printf("YES
    ");
    11         else printf("NO
    ");
    12     }
    13     return 0;
    14 }
    WA
    // 小数点后无意义的零要删去
     1 #include<stdio.h>
     2 #include<string.h>
     3 char a[1000000], b[1000000];
     4 void process(char *num)
     5 {
     6     int len=strlen(num);
     7     if(strstr(num,".")!=NULL)
     8     {
     9         while(num[--len]=='0');
    10         if(num[len]=='.')
    11             num[len]='';
    12     }
    13 }
    14 int main()
    15 {
    16     while(scanf(" %s %s", a, b)!=EOF)
    17     {
    18         process(a); process(b);
    19         if(strcmp(a,b)) printf("NO
    ");
    20         else printf("YES
    ");
    21     }
    22     return 0;
    23 }
    WA*2
    // 
     1 #include<stdio.h>
     2 #include<string.h>
     3 char a[1000000], b[1000000];
     4 void process(char *num)
     5 {
     6     int len=strlen(num);
     7     if(strstr(num,".")!=NULL)
     8     {
     9         while(num[--len]=='0');
    10         if(num[len]=='.')
    11             len--;
    12         num[++len]='';
    13     }
    14 }
    15 int main()
    16 {
    17     while(scanf(" %s %s", a, b)!=EOF)
    18     {
    19         process(a); process(b);
    20         if(strcmp(a,b)) printf("NO
    ");
    21         else printf("YES
    ");
    22     }
    23     return 0;
    24 }
    AC
    // 判断两数是否相等还可用strcmp
    // char *strstr(char *str1, char *str2); 寻找str2在str1中第一次出现的位置,返回位置指针
    
    
  • 相关阅读:
    Excel标题与索引的对应关系
    拼接LINQ动态表达式
    根据输入的模型属性表达式获取名称
    如何将页面的<br/>在Excel中正确换行
    针对VM从挂机-启动后,docker相关服务的无法使用问题!
    NIO(三):Selector选择器
    NIO(二):Channel通道
    Netty(一):netty的入门使用。
    设计模式(五):原型模式
    NIO(一):Buffer缓冲区
  • 原文地址:https://www.cnblogs.com/goldenretriever/p/10355777.html
Copyright © 2011-2022 走看看