Basic Template:
#include <iostream>
#include <cstdio>
using namespace std;
int main ()
{
int a,b;
int tem;
while (~SCANF ("%d%d", &a,&b)) {for
(int i=0;i<15;i++) {
tem=a/b;
A-=b*tem;
a*=10;
printf ("%d", tem);
if (!i)
printf (".");
}
printf ("\ n");
}
Topic Link: Http://codeforces.com/contest/900/problem/B
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL Long
using namespace std;
int main ()
{
int a,b,c;
int Tem,cnt,flag;
while (~SCANF ("%d%d%d", &a,&b,&c)) {
cnt=flag=0;
a*=10;
for (int i=0;i<1000005;i++) {
if (a==0) {if (
c==0) {
flag=1;
cnt++;
}
break;
tem=a/b;
A-=b*tem;
cnt++;
a*=10;
printf ("%d", tem);
if (tem==c) {
flag=1;
break;
}
}
if (flag)
printf ("%d\n", CNT);
else
printf (" -1\n");
}
Topic Link: VJ on UVa 202 self-opening
The code is as follows:
Even if it is decimal, it may not start with the first decimal number, so there will be errors in parentheses and the length of the Loop section, WA several times #include <iostream> #include <cstdio> #include <
Cstring> using namespace std;
int rm[1010];//The final result array int vis[1000010];//tag appears, storing the first occurrence of the position K int rec[1000010];//When k occurs, the value of divisor A is int main () {int a,b;
while (~SCANF ("%d%d", &a,&b)) {memset (vis,0,sizeof (VIS));
memset (Rec,0,sizeof (rec));
printf ("%d/%d =%d", a,b,a/b);
A=a%b;
int k=1;
while (!VIS[A]&&A)//if visited, the description is decimal, otherwise there is no cyclic solution {vis[a]=k;
Rec[k]=a;
a=a*10;
rm[k++]=a/b;
A=a%b;
printf (".");
for (int i=1;i<k&&i<=50;++i) {if (A&&a==rec[i])///When you start looping from this number, add parentheses, just expand the loop part
printf ("(");
printf ("%d", rm[i]);
} if (!a) printf ("(0");
if (k>50) printf ("...");
printf (") \ n"); printf ("%d = numberof digits in repeating cycle\n ", a?
(K-vis[a]): 1);//k minus the cycle start position} return 0;
}