Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ CodeKiller777
Ручной ввод пути к файлу (через консоль, через правку переменной в коде и т.д.) недопустим. Необходимость любых ручных действий с файлами в процессе работы программы будут обнулять решение.

## Автор решения

Чернецов Михаил Юрьевич
## Описание реализации

В качестве базы данных я использовал unordered_map, работает на хэш таблицах, учитывая то, что имена будут не слишком длинными норм. Проверял корректность даты с помощью перевода григорианской даты в юлианскую дату, затем обратно, должно быть однозначное отображение
## Инструкция по сборке и запуску решения
компилировать нужно function.cpp SummerSchool.cpp
программа принимает аргументами командной строки входной файл и выходной
в случае некорректности коммита, выводится в консоль ошибка с указанием строки, в которой ошибка.
54 changes: 54 additions & 0 deletions SummerSchool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>
#include <fstream>
#include "functions.h"
#include"structs.h"
int main(int argc, const char* argv[])
{
std::ifstream in(argv[1]);
std::ofstream out(argv[2]);

if (!isArgCorrect(in, out, argc)) { return -1; }
DataBase D;
int x = 0;
int line = 1;
while ((x = in.get()) != EOF) {
std::string name;
if (!(x > 64 && x < 91 || x > 96 && x < 123 || x == 95)) { std::cout << "incorrect name at line: " << line; return -2; }
while (x != ' ') {
if (!(x > 64 && x < 91 || x > 96 && x < 123 || x > 47 && x < 58 || x == 95)) { std::cout << "incorrect name at line: " << line; return -2; }
name.push_back(char(x)); x = in.get();
}
uint32_t counter = 0;
while (x == ' ') { x = in.get(); }
while (x != ' ' && (x > 47 && x < 58 || x > 96 && x < 123)) { x = in.get(); ++counter; }
if (counter != 7) { std::cout << "incorrect hash at line: " << line; return -2; }
uint32_t year=0;
uint32_t month=0;
uint32_t day=0;
in >> year;
in.ignore();
in >> month;
in.ignore();
in >> day;
in.ignore();
++line;
if (!isDateCorrect(year, month, day)) { std::cout << "incorrect date at line: " << line; return -2; }
uint32_t hours = 0;
uint32_t minutes = 0;
double seconds = 0;
in >> hours;
in.ignore();
in >> minutes;
in.ignore();
in >> seconds;
while (in.peek() == '\r' || in.peek() == '\n' || in.peek() == ' ') { in.ignore(); }
if (hours > 24 || hours < 0) { std::cout << "incorrect hours value at line: " << line; return -2; }
if (minutes > 60 || minutes < 0) { std::cout << "incorrect minutes value at line: " << line; return -2; }
if (seconds > 60.0 || minutes < 0.0) { std::cout << "incorrect second value at line: " << line; return -2; }
D.push(name);
//3n
}
D.up3JuniorToMiddle(out);
in.close();
out.close();
}
31 changes: 31 additions & 0 deletions functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "functions.h"
void help() {
std::cout << "input 3 argument :" << '\n';
std::cout << "program.exe inputFile.txt outputFile.txt"<<'\n';
}
bool isArgCorrect(std::ifstream& in, std::ofstream& out, int argc) {
if (argc < 2) { std::cout << "can't find input file'\n'"; help(); return false; }
if (argc < 3) { std::cout << "can't find output file'\n'"; help(); return false; }
if (!in) { std::cout << "can't read input file'\n'"; return false; }
if (!out) { std::cout << "can't write to output file'\n'"; return false; }
return true;
}
bool isDateCorrect(uint32_t year, uint32_t month, uint32_t day) {
int a = (14 - month) / 12;
int y = year + 4800 - a;
int m = month + 12 * a - 3;
int JD = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;

a = JD + 32044;
int b = (4 * a + 3) / 146097;
int c = a - 146097 * b / 4;
int d = (4 * c + 3) / 1461;
int e = c - (1461 * d) / 4;
m = (5 * e + 2) / 153;
int cd = e - (153 * m + 2) / 5 + 1;
int cm = m + 3 - 12 * (m / 10);
int cy = 100 * b + d - 4800 + m / 10;

if (cd != day || cm != month || cy != year) { return false; }
return true;
}
11 changes: 11 additions & 0 deletions functions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef MYLIB_H
#define MYLIB_H
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
bool isArgCorrect(std::ifstream& in, std::ofstream& out, int argc);
bool isDateCorrect(uint32_t year, uint32_t month, uint32_t day);
#endif
35 changes: 35 additions & 0 deletions structs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef MYLIB_HR
#define MYLIB_HR
#include "functions.h"
#include <unordered_map>
class DataBase {
/*std::set<std::string> S;*/
std::unordered_map<std::string, uint32_t> M;
public:
DataBase() = default;
void push(std::string& name) {
/*auto it = S.find(name);
if (it != S.end()) { ++M[name]; }
else { S.insert(name); ++M[name]; }*/
M[name] += 1;
}
void up3JuniorToMiddle(std::ofstream& out) {
int count = 3;
if (M.size() < 3) { count = M.size(); }
while (count != 0) {
int max = 0;
std::string name;
--count;
for (auto it = M.begin(); it != M.end(); ++it) {
if (it->second > max) {
max = it->second;
name = it->first;
}
}
if (count == 0) { out << name; }
else { out << name << ' '; }
M[name] = 0;
}
}
};
#endif MYLIB_HR