Problem here
Solution
#include <iostream>
#include <memory.h>
#include <string>
using namespace std;
int main(){
int n, m;
int len[1001];
while(cin >> n >> m){
if(n == 0 && m == 0)
break;
memset(len, -1, sizeof(len));
len[n] = 0;
string output = ".";
while(n){
n *= 10;
output += (n/m) + '0';
n %= m;
if(len[n%m] != -1)
break;
len[n] = output.length()-1;
}
for(int i = 0; i < output.length(); i++){
if(i > 0 && (i%50)==0 )
cout << endl;
cout << output[i];
}
cout << endl;
if(n != 0)
cout << "The last " << output.length() - len[n%m] - 1 << " digits repeat forever." << endl;
else
cout << "This expansion terminates." << endl;
//UVa 要再output一空行
//cout << endl
}
return 0;
}
No comments:
Post a Comment