IoTgod 5 years ago
parent 242fe18dfe
commit 3799302743
  1. BIN
      a.exe
  2. 101
      as1.cpp

BIN
a.exe

Binary file not shown.

@ -193,44 +193,105 @@ int Fraction::get_common_divisor() const
return t_top;
}
/*
void get_decimal_repeating_part(double f)
{
double t_dec = f - (int)f;
}
*/
int get_double_decimals_length(double d)
unsigned long int transfer_double_decimals_to_unsigned_long_int_for_single(const double& d)
{
ostringstream out;
//out.precision(18);//覆盖默认精度
out<<d;
string s= out.str();
return s.length();
if(d > 0.09999999999 && d < 0.100000000001) return 1;
if(d > 0.19999999999 && d < 0.200000000001) return 2;
if(d > 0.29999999999 && d < 0.300000000001) return 3;
if(d > 0.39999999999 && d < 0.400000000001) return 4;
if(d > 0.49999999999 && d < 0.500000000001) return 5;
if(d > 0.59999999999 && d < 0.600000000001) return 6;
if(d > 0.69999999999 && d < 0.700000000001) return 7;
if(d > 0.79999999999 && d < 0.800000000001) return 8;
if(d > 0.89999999999 && d < 0.900000000001) return 9;
return 0;
}
/* 两位以上*/
unsigned long int transfer_double_decimals_to_unsigned_long_int(double d)
unsigned long int transfer_double_decimals_to_unsigned_long_int(const double& d)
{
if(transfer_double_decimals_to_unsigned_long_int_for_single(d)) return transfer_double_decimals_to_unsigned_long_int_for_single(d);
unsigned long int t = (unsigned long int)(d*(1000000000));
while(d != 0 && t % (t/10) == 0 && t > 100) t /= 10;
while(d != 0 && (t % (t/10) == 0 || t % (t/10) == 9) && t > 100) t /= 10;
if((unsigned long int)(d*(1000000000)) % 1000 == 999) return ++t;
return t;
}
inline unsigned long int get_double_decimals_part(double d)
inline unsigned long int get_double_decimals_part(const double& d)
{
return transfer_double_decimals_to_unsigned_long_int(d-floor(d));
double t;
return transfer_double_decimals_to_unsigned_long_int(fabs(d) - floor(fabs(d)));
}
inline unsigned long int get_double_integer_part(const double& d)
{
return (unsigned long int)floor(fabs(d));
}
inline bool get_double_is_negative(const double& d)
{
return (d < 0)? true : false;
}
inline unsigned short get_one_decimal(const unsigned long int& t, unsigned short point)
{
return (t / (unsigned int)pow(10, point - 1)) % 10;
}
unsigned short get_long_int_length(long int t)
{
int count = 0;
while(t){
t /= 10;
count++;
}
return count;
}
unsigned int get_repeart_part(const unsigned long int& t)
{
unsigned short i = 1;
unsigned short len = get_long_int_length(t);
while(i < len){
unsigned short count = 0;
while(i < len && get_one_decimal(t, ++i) != get_one_decimal(t, 1));
for(unsigned short j = 1; j < i; j++){
if(get_one_decimal(t, j) == get_one_decimal(t, j + i - 1)) count++;
}
if(count == i - 1) return t % (unsigned int)pow(10, i - 1);
}
return 0;
}
/*
void repeated_decimal_to_fraction(double d)
{
get_double_integer_part(d)
unsigned long int decimal = get_double_decimals_part(d);
unsigned int body = get_repeart_part(decimal);
for(unsigned short i = get_long_int_length(body); i < )
}
*/
int main()
{
vector<int> a;
@ -246,8 +307,8 @@ int main()
// for(int i =0; i < a.size(); i++) cout << a[i] <<endl;
//try{
cout << get_double_decimals_part(34234)<<endl;
//cout << f.val();
cout << get_repeart_part(132123354) << endl ;
//}catch(const char* msg){
// cerr << msg << endl;
//}

Loading…
Cancel
Save