B-big or small?Time
limit:5000MS
Memory Limit:65535KB
64bit IO Format:
Description
Enter two real numbers, judging the first number is large, the second number is the same size. The format of each number is: [ integer part ].[ Sub-number part ]
For simplicity, both the integer and fractional parts are guaranteed to be non-null, and the integer part does not have a leading 0. However, the number of decimal parts can last 0, so 0.0 and 0.000 are the same size.
Input
The input contains no more than 20 sets of data. Each group of data contains one row, with two real numbers (formatted as described earlier). Each real number consists of no more than 100 characters.
Output
For each set of data, if the first number is large, the output is "bigger". If the first number is small, output "Smaller". If the two numbers are the same, the output is "same".
Sample Input
1.0 2.00.00001 0.000000.0 0.000
Sample Output
Case 1:smallercase 2:biggercase 3:same
All right....... Because the team brush problem I was the former brush, so this water problem was first I saw a, test instructions all Chinese is nothing to explain. The number of digits is 100 characters, so you have to use a string to handle, after the decimal point of the auto-0 to facilitate the final judgment is the same, and then the decimal point before the number of people who are large, the same number of digits from the beginning of the comparison, has been compared to the results. The format of the input has been fixed as "integer part." So don't worry about a number that doesn't have a decimal point, you can just compare it.
The following code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Chara[ the],b[ the];intMaxintAintb) { returnA>b?a:b;}intMain () {intLen1,len2; inti,j; intk=0; intd1,d2; intT; while(SCANF ("%s", a)! =EOF) {scanf ("%s", B); Len1=strlen (a); Len2=strlen (b); for(i=len1;i<102; i++) {A[i]='0'; } for(i=len2;i<102; i++) {B[i]='0'; } t=0; K++; D1=len1; D2=Len2; cout<<" Case"<<k<<": "; for(i=0; i<len1;i++) { if(a[i]=='.') {D1=i; Break; } } for(i=0; i<len2;i++) { if(b[i]=='.') {D2=i; Break; } } if(d1>D2) {cout<<"bigger"<<Endl; T=2; } Else if(d1<D2) {cout<<"Smaller"<<Endl; T=2; } Else { for(i=0; I<max (len1,len2); i++) { if(a[i]>B[i]) {T=1; Break; } Else if(a[i]<B[i]) {T=-1; Break; } } } if(t==0) cout<<"same"<<Endl; Else if(t==1) cout<<"bigger"<<Endl; Else if(t==-1) cout<<"Smaller"<<Endl; } return 0;}
The 11th annual "Blue Fox network Cup" computer Program design contest for college students in Hunan province B-big or small? String water problem