标签:div amp size res sp algorithm return public
很水,但是需要练速度反映。。。15分钟全部写对!!!!!!!!!!!!
#include <assert.h> #include <algorithm> #include <vector> using namespace std; class Decimal { public: int integer; bool recycle; vector<int> decimal; }; void toDecimal(int dividend, int divisor, Decimal& decimal) { decimal.integer = dividend / divisor; int remainder = dividend % divisor, recycle = 0, end = 0, curbit = 0; while (remainder) { int cur = remainder*10/divisor; decimal.decimal.push_back(cur); if (recycle || curbit > 0) recycle = decimal.decimal[recycle] == cur ? recycle + 1 : 0; if (curbit > 0 && recycle == end) { decimal.decimal.resize(recycle); decimal.recycle = true; return; } ++curbit; if (!recycle) end = curbit; remainder = (remainder * 10) % divisor; } decimal.recycle = false; } int main() { Decimal dec; toDecimal(12,8,dec); return 0; }
标签:div amp size res sp algorithm return public
原文地址:http://blog.csdn.net/taoqick/article/details/38542685