1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <stdio.h> #include <stdlib.h> #include <string.h> long long int K,I,Lu,Ru,V,Ld,Rd,MyCase,D,U; int J; char MyString[12]; long long int MyGCD(long long int A,long long int B) { long long int MyTemp; while(A%B) { MyTemp=A; A=B; B=MyTemp%B; } return B; } /** long long int MyLCM(long long int A ,long long int B) { return (A*B)/(MyGCD(A,B)); } * **/ long long int MyPow(long long int N) { long long int MyTemp=1; while(N--) { MyTemp=MyTemp*10; } return MyTemp; } int main() { while (EOF!=scanf("%d",&J)) { if (J==-1) break; scanf("%s",MyString); I=strlen(MyString); if (J == 0) { V=atoi(MyString+2); U = MyPow(I - 2); } else { int K = I - 2 - J; MyString[2+K+J]='\0'; Lu=atoi(MyString+2); MyString[2 + K] = '\0'; Ru = atoi(MyString+2); Ld=MyPow(K); Rd=MyPow(I-2); V = Lu - Ru; U = Rd - Ld; } D = MyGCD(V, U); printf("Case %lld: %lld/%lld\n",++MyCase,V/D,U/D); /* %I64d for Windows */ } return 0; } |
Direct link: https://paste.plurk.com/show/210623