A == B ?

来源:互联网 发布:淘宝上的中药能买吗 编辑:程序博客网 时间:2024/06/01 20:50

A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 64960    Accepted Submission(s): 10164


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 22 23 34 3
 

Sample Output
NOYESYESNO

注意细节,注意取值范围,小数点

#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define LEN 100000int main() {    char a[LEN];    char b[LEN];    int lena, lenb, len, i;    while(cin >> a >> b) {        lena = 0;        lenb = 0;        len = strlen(a);        len--;        for(i = 0; i <= len; i++) {            if(a[i] == '.') {                lena = i;                break;            }        }        while(a[len] == '0' && len > lena && lena != 0) {            a[len] = '\0';            len--;        }        if(a[len] == '.') {           a[len] = '\0';        }        len = strlen(b);        len--;        for(i = 0; i <= len; i++) {            if(b[i] == '.') {                lenb = i;                break;            }        }        while(b[len] == '0' && len > lenb && lenb != 0) {            b[len] = '\0';            len--;        }        if(b[len] == '.') {            b[len] = '\0';        }        if(strcmp(a, b) == 0) {            cout << "YES" << endl;        }        else {            cout << "NO" << endl;        }    }    return 0;}



0 0