zoukankan      html  css  js  c++  java
  • 2054 A == B ?

    Problem Description
    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
     1 #include<iostream>
     2 #include <cstring>
     3 #include <stdio.h>
     4 using namespace std;
     5 const int MAX = 100000;
     6 void zero(char *str)//去后前面的零,保留小数点,没小数点的给他加一个
     7 {
     8     int i,len;
     9     len = strlen(str);
    10     char *p = strchr(str,'.');
    11     if(p == NULL)
    12     {
    13         str[len] = '.';
    14         str[len+1] = '';
    15     }
    16     else
    17     {
    18         for(i=len-1; i>=0; i--)
    19         {
    20             if(str[i] != '0')
    21             {
    22                 str[i+1] = '';
    23                 return;
    24             }
    25         }
    26     }
    27 }
    28 int main()
    29 {
    30     char num1[MAX];
    31     char num2[MAX];
    32     char *p,*q;
    33     while(scanf("%s%s",num1,num2) != EOF)
    34     {
    35         zero(num1);
    36         zero(num2);
    37         p=num1;
    38         q=num2;
    39         while(*p=='0')//去掉前面的零
    40         {
    41             p++;
    42         }
    43         while(*q=='0')//去掉前面的零
    44         {
    45             q++;
    46         }
    47         if(!strcmp(p,q))
    48         {
    49             printf("YES
    ");
    50         }
    51         else
    52         {
    53             printf("NO
    ");
    54         }
    55     }
    56     return 0;
    57 }
    View Code

    函数strchr(s,'c')的作用是(查找字符串s中首次出现字符c的位置)

  • 相关阅读:
    POJ 1185 状压DP
    POJ 1321
    hdu 1384 查分约束
    hdu 2196 树形dp
    hdu 4612 双联通缩点+树形dp
    poj 3469 最小割模板sap+gap+弧优化
    hdu 4858 容器的简单模拟
    hdu 4857 逆向拓扑排序+反向输出
    isap算法模板poj 1273gap+弧优化 最大流
    ISAP 算法的学习
  • 原文地址:https://www.cnblogs.com/wang-ya-wei/p/5313061.html
Copyright © 2011-2022 走看看