Created
September 13, 2008 08:16
-
-
Save dazza/10582 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
using namespace std; | |
int visit[1000002]; | |
unsigned long long indes [1000002]; | |
char buf[1000000]; | |
int main() | |
{ | |
ifstream fin("fracdec.in"); | |
ofstream fout("fracdec.out"); | |
unsigned long long N,D; | |
fin>>N>>D; | |
// | |
// N=1;D=99991; | |
// | |
fout<<N/D<<'.'; | |
if (!N%D) | |
{ | |
fout<<N%D<<endl; | |
return 0; | |
} | |
unsigned long long S = N/D; | |
unsigned long long num = 0; | |
while (S) | |
{ | |
num++; | |
S/=10; | |
} | |
if(N/D==0) num++; | |
for (unsigned long long i= 0 ; ; i++) | |
{ | |
N = N % D*10; | |
int sh = N / D; | |
if (N%D==0) | |
{ | |
buf[i] = '0'+sh; | |
buf[i+1] = '\0'; | |
break; | |
} | |
else | |
{ | |
if (visit[N]&&buf[indes[N]]==sh+'0') | |
{ | |
buf[i+1] = ')'; | |
buf[i+2] = '\0'; | |
unsigned long long j = i; | |
for ( ; j>indes[N] ;j--) | |
{ | |
buf[j] = buf[j-1]; | |
} | |
buf[j] = '('; | |
break; | |
} | |
else | |
{ | |
visit[N] = 1; | |
indes[N] = i; | |
buf[i] = '0' + sh; | |
} | |
} | |
} | |
num++;//as '.' | |
unsigned long long i = 0; | |
while (buf[i]) | |
{ | |
if ((i+num)%76 == 0) | |
{ | |
fout<<endl; | |
} | |
fout<<buf[i++]; | |
} | |
fout<<endl; | |
fin.close(); | |
fout.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment