#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum mod {decrease, increase};
mod status;
string ntime;
string str_input;
void choice_mod();
void choice_newtime();
void set_newtime();
int main()
{
setlocale(LC_CTYPE, "Russian");
choice_mod();
choice_newtime();
set_newtime();
system("pause");
}
void choice_mod ()
{
char c;
cout << "Какой режим вы хотите использовать?\n"
<< "Если нужно использовать режим увелечения времени, то напишите +\n"
<< "А если нужен режим уменьшения времени, то напишите -\n";
do
{
cin >> c;
if((c != '+') && (c != '-'))
cout << "Неправильный символ! Повторите ввод.\n";
}
while((c != '+') && (c != '-'));
if(c == '+')
status = increase;
else
status = decrease;
}
void choice_newtime()
{
size_t t_size = 12;
size_t count_symb = 0;
size_t count_num = 0;
size_t count_sum;
cout << "Введите начальное время в формтае - 00:00:00,000 час/минута/секунда/миллисекунда\n";
do
{
getline(cin, ntime);
if(ntime.length() > 0){
for(size_t i = 0; i < ntime.length() && !(i > t_size); i++)
{
if((i == 2 && ntime[i] == ':') || (i == 5 && ntime[i] == ':') || (i == 8 && ntime[i] == ',') && (count_symb <= 3))
{
++count_symb;
}
if((i != 2 || i != 5 || i != 8) && (ntime[i] >= '0' && ntime[i] <= '9') && (count_num <= 9))
{
++count_num;
}
}
cout << "\n" << count_symb;
cout << "\n" << count_num;
cout << "\n";
count_sum = count_symb + count_num;
if(count_sum < t_size || count_sum > t_size)
{
count_symb = 0;
count_num = 0;
ntime = "";
cout << "Неправльные данные! Повторите ввод.\n";
}
}
}
while(count_sum != t_size);
}
void set_newtime()
{
string input_filename = "1.srt";
string output_filename = "2.srt";
ifstream input;
ofstream output;
input.open("D:\\subtitles\\Release\\" + input_filename);
output.open("D:\\subtitles\\Release\\" + output_filename);
while(input)
{
getline(input, str_input);
if(str_input[2] == ':' && str_input[5] == ':')
{
for(int i = 0; i < str_input.length(); i+=17)
{
for(int j = 0; j < ntime.length(); j++)
{
if((str_input[j+i] != ':') && (str_input[j+i] != ','))
{
if(status == increase)
{
if((char((str_input[j+i] + ntime[j]) - 48)) > '9')
{
if((j == 0) || (j == 17))
{
cout << "достигнуто максимальное время";
}
else
{
str_input[j+i-1]++;
str_input[j+i] = ntime[j] - 1;
}
}
else
{
str_input[j+i] = char((str_input[j+i] + ntime[j]) - 48);
}
}
if(status == decrease)
{
if(char((str_input[j+i] - ntime[j]) + 48) < '0')
{
if((j == 0) || (j == 17))
{
str_input[j+i] = '0';
cout << "Достигнуто минимальное время";
}
else
{
if((str_input[j+i-1] > '0') && (str_input[j+i-1] <= '9'))
{
str_input[j+i-1]--;
str_input[j+i] = char(((str_input[j+i] - 38) - (ntime[j] - 48)) + 48);
str_input[j+i] = '0';
}
else
if(((str_input[j+i-1] == ':') || (str_input[j+i-1] == ',')) && (str_input[j+i-2] > '0'))
{
str_input[j+i-2]--;
str_input[j+i] = char(((str_input[j+i] - 38) - (ntime[j] - 48)) + 48);
str_input[j+i] = '0';
}
}
}
else
{
str_input[j+i] = char((str_input[j+i] - ntime[j]) + 48);
}
}
}
}
}
}
str_input.push_back('\n');
output.write(str_input.c_str(), str_input.size());
}
}