Problem Description Give You both numbers A and B, if a is equal to B, you should print "YES", or print "NO".
Input Each test case contains 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
Author 8600 && XHD
Source Celebration Cup warm up
Recommend
Linle | We have carefully selected several similar problems for you:2052 2055 2053 2056 2051
Analysis: The problem involves large numbers and decimal points, it can not be a simple comparison. Timeout code:
#include <stdio.h> #include <string.h> char a1[15000],a2[15000],b1[15000],c1[15000],b2[15000],c2[15000]
;
int main () {int p1,p2,j,l,t1,i,t2,m1,m2,q1,q2;
while (scanf ("%s%s", A1,a2)) {j=0;l=0;
m1=m2=0;
P1=strlen (A1);
P2=strlen (A2);
for (i=0;i<p1;i++) if (a1[i]== '. ')
{m1=1;break;
}//printf ("%d\n", M1);
if (m1==0) {for (i=0;i<p1;i++) b1[j++]=a1[i];
b1[j]= ' + ';
for (i=0;i<j;i++)//printf ("%c", B1[i]);
} else {for (i=p1-1;i>=0;i--) if (a1[i]!= ' 0 ') {t1=i;
Break
} if (a1[t1]== '. ')
{for (i=0,j=0;i<=t1-1;i++) b1[j++]=a1[i];
b1[j]= ' + ';
for (i=0;i<t1-1;i++)//printf ("%c", B1[i]);
printf ("1\n"); } else{for (i=i-1;a1[i]!= '. ';
i--) B1[j++]=a1[i];
b1[j]= ' + ';
for (i=i-1;i>=0;i--) c1[l++]=a1[i];
c1[l]= ' + ';
for (i=0;i<l;i++)//printf ("%c", C1[i]);
}} for (i=0;i<p2;i++) if (a2[i]== '. ')
{m2=1;break; } if (m2==0) {for (i=0,j=0;i<p2;i++) b2[j++]=a2[i];
b2[j]= ' + ';
for (i=0;i<j;i++)//printf ("%c", B2[i]);
} else {j=0;
for (i=p2-1;i>=0;i--) if (a2[i]!= ' 0 ') {t2=i;
Break
} if (a2[i]== '. ')
{q2=i;
for (i=0,j=0;i<=q2-1;i++) b2[j++]=a2[i];
b2[j]= ' + ';
for (i=0;i<j;i++)//printf ("%c", B2[i]); } else{for (i=i-1,j=0;a2[i]!= '. ';
i--) B2[j++]=a2[i];
b2[j]= ' + ';
for (i=i-1,l=0;i>=0;i--) c2[l++]=a2[i];
c2[l]= ' + ';
}} if (strcmp (B1,B2) ==0&&strcmp (C1,C2) ==0) printf ("yes\n");
else printf ("no\n");
} return 0; }
This code opens up four arrays of storage. But it's a timeout code .....
So it's a different way. AC Code:
#include <stdio.h>
#include <string.h>
char a[150000],b[150000];
void f (char *s)
{
int lens;
Lens=strlen (s);
if (STRCHR (S, '. ')! =null)
{
while (s[--lens]== ' 0 ');
if (s[lens]== '. ') lens--;
s[lens+1]= ' + ';
}
}
int main ()
{
while (scanf ("%s%s", A, b) ==2)
{
F (a);
f (b);
if (strcmp (b) ==0) printf ("yes\n");
else printf ("no\n");
}
return 0;
}