HDU2054_A == B ?【模拟题】【大数】【水题】

A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 64243    Accepted Submission(s): 10061

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

题目大意:给你两个数A和B,判断A和B是否相等,若相等输出"YES",

否则输出"NO"。

思路:题目没有给出A、B的数据规模,这里就是个大数题。把A、B用

字符数组存起来,标记A、B的正负号,若为正,则标记为1,若为负,

则标记为0,将字符数组内的‘-‘赋值为‘0‘,然后将整数前的零和小数部分

后边的零清除,然后用数组将整数部分和小数部分分别存起来。之后分别

比较A、B的整数部分和小数部分是否相等。注意A、B可能为整数或是小

数,尤其注意A、B可能会在整数部分前边有N个零或者小数部分后边有N

个零,比如00012、123.123000、0.00、012.200等等。具体解题过程

看下面代码。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char A[20020],B[20020];
char a[20020],aa[20020],b[20020],bb[20020];
int main()
{
    int flagA,flagB,lenA,lenB,markA,markB;
    while(~scanf("%s%s",A,B))
    {
        memset(a,0,sizeof(a));//存A的整数部分
        memset(b,0,sizeof(b));//存B的整数部分
        memset(aa,0,sizeof(aa));//存A的小数部分
        memset(bb,0,sizeof(bb));//存B的小数部分
        flagA = flagB = 1;//标记正负数,1为整数,0为负数
        markA = markB = 0;//标记小数点,1为有小数点,0为没有小数点 

		if(A[0] == '-')//标记并清除A、B的正负号
        {
            flagA = 0;
            A[0] = '0';
        }
        if(B[0] == '-')
        {
            flagB = 0;
            B[0] = '0';
        }

        lenA = strlen(A);
        lenB = strlen(B);
        int numa = 0,i;

        for(i = 0; i < lenA; i++)//清除A的整数部分前面的零
            if(A[i]!='0')
                break;
        if(i==lenA || A[i]=='.')//若整数部分全为0,则数组a为"0"
            a[0] = '0';
        for(; i < lenA; i++)//用数组a记录A的整数部分
        {
            if(A[i]!='.')
                a[numa++] = A[i];
            else
            {
                markA = 1;
                break;
            }
        }
        int j,numaa = 0;
        for(j = lenA-1;j > i; j--)//清除A小数部分后边的零
            if(A[j]!='0')
                break;
        if(j == i)//若小数部分全为0,则数组aa为"0"
            aa[0] = '0';
        for(;j > i; j--)//用数组aa记录A的小数部分
        {
            aa[numaa++] = A[j];
        }
		//B和A的处理一样
        int k,l;
        for(k = 0; k < lenB; k++)
            if(B[k]!='0')
                break;
        if(k == lenB || B[k]=='.')
            b[0] ='0';
        int numb = 0;
        for(; k < lenB; k++)
        {
            if(B[k]!='.')
                b[numb++] = B[k];
            else
            {
                markB = 1;
                break;
            }

        }

        int numbb = 0;
        for(l = lenB-1;l > k; l--)
            if(B[l]!='0')
                break;
        if(l==k)
            bb[0]='0';
        for(;l > k; l--)
        {
            bb[numbb++] = B[l];
        }

        if(markA == 0)
            aa[0] = '0';
        if(markB == 0)
            bb[0] = '0';
        if(flagA==flagB && strcmp(a,b)==0 && strcmp(aa,bb)==0)//判断A、B是否相等
            printf("YES\n");
        else
            printf("NO\n");
        memset(A,0,sizeof(A));
        memset(B,0,sizeof(B));
    }

    return 0;
}
时间: 2024-08-06 08:34:51

HDU2054_A == B ?【模拟题】【大数】【水题】的相关文章

HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 64256    Accepted Submission(s): 18286 Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in o

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

涨姿势题2_水题_两种解法

Problem Description 涨姿势题就是所谓的优化题,在组队赛中,队伍发现了一题水题,那么应该交给谁去处理?作为处理水题的代码手,应该具备什么样的素养?1,要快,水题拼的就是速度!2,不能卡水题!水题都卡,绝对不是一个代码手的风范!3,不能出错,错一次即罚时20分钟,对于水题来讲是致命的!4,要能看出来一题是水题!没有这条,上面三条都是没有意义的! 如果你希望你成团队中一个合格的代码手,那么这套题是你最好的选择,快AC吧! 本系列即是为了提高水题代码手的素养而准备的!水题经常需要用到

HDU5742 It&#39;s All In The Mind(思维题,水题)

Problem Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence: 1. For every i∈{1,2,...,n}, 0≤ai≤100.

HDU-1047-Integer Inquiry(Java大数水题 &amp;&amp; 格式恶心)

Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14886    Accepted Submission(s): 3811 Problem Description One of the first users of BIT's new supercomputer was Chip Diller. He e

课后题 3-3 水题

Digit Counting Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Download as PDF Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integ

HDU2076 夹角有多大(题目已修改,注意读题)【水题】【计算几何】

夹角有多大(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10194    Accepted Submission(s): 4072 Problem Description 时间过的好快,一个学期就这么的过去了,xhd在傻傻的看着表,出于对数据的渴望,突然他想知道这个表的时针和分针的夹角是多少.现在xhd知道的

HDU 5744 Keep On Movin (思维题,水题)

Problem Description Professor Zhang has kinds of characters and the quantity of the i-th character is ai. Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximize the length of the shortest palindro

F题(水题)

给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. 例如: 1 7 6 3 1.i = 1, j = 3,对应的数为7 6 3,最大的数为7.(该问题也被称为RMQ问题) Input第1行:1个数N,表示序列的长度.(2 <= N <= 10000) 第2 - N + 1行:每行1个数,对应序列中的元素.(0 <= Sii <= 10^9) 第N + 2行:1个数Q,表示查询的数量.(2 <= Q <= 10000)

OpenJudgeP1.7.10:简单密码__(刷题)_水题

因为本人很懒,不想去找什么,ASCII码的规律...... 就又开了一个cpp,打了一份if&else 的表. 1 #include <bits/stdc++.h> 2 using namespace std; 3 char a[50]; 4 char b[50]; 5 6 /*A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 7 V W X Y Z A B C D E F G H I J K L M N O P Q R S T U