#include <iostream>
#include <math.h>
#include <sstream>
#include <iomanip>
using namespace std;
int Convert(float input)
{
int temp = input;
input = fabs(input - temp);
stringstream ss;
string str;
ss << setprecision(5) << input;
ss >> str;
if (str != "0")
{
str = str.substr(2);
}
return atoi(str.c_str());
}
bool Uslovie(float input)
{
int convert_input = Convert(input);
int sum = 0;
while (convert_input != 0)
{
sum += convert_input % 10;
convert_input /= 10;
}
if (sum % 3 == 0)
{
return true;
}
return false;
}
int ReverseSearch(float input[], int length)
{
for (int i = length - 1; i >= 0; i--)
{
if (Uslovie(input[i]))
{
return i;
break;
}
}
return length;
}
float GetNumber()
{
cout << "Enter a float ";
float o;
cin >> o;
return o;
}
int main()
{
//Smirnova
//i,m-индексы для сортировки/вывода массива
//r-дополнительная временная переменная для сортировки массива "Пузырьком"
//o-используется для получения числа с клавиатуры
float S[10] = { 12.9,-12.0,-34.87,6.45,0.4,-8.98978,-56.8,7.56,42.8, 21.4 };
int length = sizeof(S) / sizeof(*S);
cout << "Massive" << "\n";
cout.precision(3);
for (int i = 0; i < length; i++)
{
cout << S[i] << " ";
}
cout << "\n";
cout << "Sorted massive" << "\n";
for (int i = 0; i < length - 1; i++)
{
for (int m = i + 1; m < length; m++)
{
if (S[i] < S[m])
{
float r;
r = S[i];
S[i] = S[m];
S[m] = r;
}
}
}
for (int i = 0; i < length; i++)
{
cout << S[i] << " ";
}
cout << "\n";
int deleted = ReverseSearch(S, length);
cout << "deleted = " << deleted << "\n";
float o = GetNumber();
if (deleted != length)
{
S[deleted] = o;
}
else
{
float temp[11];
for (int i = 0; i < length; i++)
{
temp[i] = S[1];
}
temp[11] = o;
delete[] S;
float S[11];
for (int i = 0; i < length + 1; i++)
{
S[i] = temp[i];
}
delete[] temp;
}
length = sizeof(S) / sizeof(*S);
for (int i = 0; i < length - 1; i++)
{
for (int m = i + 1; m < length; m++)
{
if (S[i] < S[m])
{
float r;
r = S[i];
S[i] = S[m];
S[m] = r;
}
}
}
cout << "Sorted massive with number from User" << "\n";
for (int i = 0; i < length; i++)
{
cout << S[i] << " ";
}
}