102

2000_1

 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
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int b[105],c[105];
bool p1;
int main(){
    int i,j,j1,j2,p,q;
    cin>>q>>p;j=1;p1=true;b[j]=q;j1=0;
    while (q>0&&p1){
        j1++;
        c[j1]=q*10/p;
        q=q*10-c[j1]*p;
        if(q>0){
            j2=1;
            while(b[j2]!=q&&j2<=j)j2++;
            if (b[j2]==q){
                p1=false;cout<<"0.";
                for (int i = 1; i <=j2-1; i++)cout<<c[i];
                cout<<'{';
                for (i =j2; i<=j1; i++)cout<<c[i];
                cout<<'}';           
            }
            else{j++,b[j]=q;}            
        }
        if(q==0){
            cout<<"0.";
            for ( i = 1; i <=j1 ; i++)cout<<c[i];
            cout<<endl;
        }
    }
    
}
Scroll to Top