than size _ format

Source: Internet
Author: User
Tags strcmp
Time limit than size: 3000 MS | Memory limit: 65535 KB Difficulty: 2 description

Give you two very large numbers, can you tell the size of their two numbers?

For example 123456789123456789 to be greater than 123456 enter one row for each set of test data, and enter two 1000-bit 10 integer a,b
The data guarantees that the input a,b does not have a prefix of 0.
If input 0 0 indicates the end of input. The number of test data sets is not more than 10 sets of output if the a>b output "a>b", if a<b output "a<b", if equal output "a==b". Sample input

111111111111111111111111111 88888888888888888888
-1111111111111111111111111  22222222
0 0
Sample output
A>b
A<b
For this problem deep feeling, in Nanyang OJ submitted 8 times just congratulations, to the last found error let me no words, the following is I write the AC code.
#include <stdio.h> #include <string.h> char a[1005],b[1005]; int main () {int t=0;  while (scanf ("%s%s", &a,&b) && (a[0]!= ' 0 ' | | b[0]!= ' 0 ')  {   if (a[0]== '-' &&b[0]== '-')    {    if (
Strlen (a) >strlen (b))     printf ("a<b\n", a,b);
    else if (strlen (a) <strlen (b))     printf ("a>b\n", a,b);     else     {     if (strcmp (a,b) >0)  
    printf ("a<b\n", a,b);
     else if (strcmp (a,b) <0)      printf ("a>b\n", a,b);
     else      printf ("a==b\n", a,b);
&NBSP;&NBSP;&NBSP;&NBSP}   &nbsp}   else if (a[0]!= '-' &&b[0]!= '-')   {         if (strlen (a) >strlen (b)) &NBSP;&NBSP;&NBSP;&NBsp;printf ("a>b\n", a,b);
    else if (strlen (a) <strlen (b))     printf ("a<b\n", a,b);     else     {     if (strcmp (a,b) >0)  
    printf ("a>b\n", a,b);
     else if (strcmp (a,b) <0)      printf ("a<b\n");
     else      printf ("a==b\n"); &NBSP;&NBSP;&NBSP;&NBSP}  &nbsp}   else   {  if (a[0]== '-' &&b[0]!= '-'
)   printf ("a<b\n", a,b);
  else   printf ("a>b\n", a,b);
     }  t++;
 if (t==10)  break;
  &nbsp        return 0; }
The idea of this problem is not difficult, with a character array simulation on the line, enumerate all the situations violently; for two negative numbers, compare the length of the string, who is the smaller, and if the length is equal, call the strcmp () function to compare; if one is negative, it is directly judged size; two integers, as opposed to two negative numbers;
For me Nanyang OJ did not pass, the title requires the output character a<b,a>b,a==b. And I have the output of two, this error for a morning, and the test data is up to 10 groups, so not more than 10 groups, this should be taken into account.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.