Background: 1_wa: Forget that there is a blank line between each answer! 2_wa: I don't see a space on either side of the equals sign!!!!!!!!
Idea: integers and decimals are separated, integers are divided directly by integer division, fractional part: numerator = (numerator% denominator) *10. and storing each molecule in str[0], the fractional part begins to circulate when there are molecules that have already appeared!
Learn:
1. Pigeon principle (drawer principle, Dirichlet principle):
Simple description: If there are n cages, n+1 only pigeons live, then at least one cage has two pigeons.
A generalized description ( described with a Gaussian function ): Divide n elements into M-sets, at least one set of elements greater than or equal to [(n-1)/m]+1.
For the subject, a%b up to b-1 a case, according to the principle of nest pigeons, the number of links is less than equal to b-1.
#include <stdio.h>int str[2][10000]; int main (void) { int a,b,intger; while (scanf ("%d%d", &a,&b)!=eof) { int count=0,start,aa=a; intger=a/b; a=a%b; while (1) { a*=10; for (int i=0;i < count;i++) { if (A==str[0][i]) { start=i; goto L1; } } Str[0][count]=a; str[1][count++]=a/b; a=a%b; } L1: printf ("%d/%d =%d.", Aa,b,intger); for (int i=0;i < start;i++) { printf ("%d", Str[1][i]); } if (count<=50) { printf ("); for (int i=start;i < count;i++) { printf ("%d", Str[1][i]); } printf (") \ n"); } else{ printf ("("); for (int i=start;i < start+50;i++) { printf ("%d", Str[1][i]); } printf ("...) \ n "); } printf (" %d = number of digits in repeating cycle\n\n", count-start); }
UVa 202 large number of divisions