Advertisement
immuntasir

UVA 202

Aug 22nd, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. int main() {
  3. int a,b;
  4. while (scanf("%d %d", &a, &b)!=EOF) {
  5. char str[1000];
  6. int cnt;
  7. int z = a/b;
  8. int c=a;
  9. a = a%b;
  10. for (cnt=0; cnt<900;cnt++) {
  11. str[cnt] = ((a*10)/b) + '0';
  12. a = (a*10)%b;
  13. }
  14.  
  15. str[cnt] = 0;
  16. int len,i,j,found = 0, k;
  17. for (i=0;i<100 && !found;i++) {
  18. for (len=1;len<=(800-i-1) && !found;len++) {
  19. int valid=1;
  20. for (j=i;j<=i+len && valid;j++) {
  21. if (str[j] != str[j+len]) valid = 0;
  22. }
  23. if (valid) {
  24. found = 1;
  25. printf("%d/%d = %d.",c,b, z);
  26. for (k=0;k<j-len-1;k++)printf("%c", str[k]);
  27. printf("(");
  28. for (k=j-len-1; k<j-1 && k<50;k++) printf("%c", str[k]);
  29. if (k<50) printf(")\n");
  30. else printf("...)\n");
  31. printf(" %d = number of digits in repeating cycle\n", len);
  32. printf("\n");
  33. }
  34. }
  35. }
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement