tahamajs's picture
download
raw
8.38 kB
#include <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include <stdio.h>
using namespace std;
int showLongestNote(vector<vector<string>> note);
void showByDay(vector<vector<string>> note, string temp);
void BestDay(vector<vector<string>> note);
void printNote(vector<vector<string>> note, int x);
void printShortNote(vector<vector<string>> note, int x);
vector<int> spliteStringToInt(string time);
string oldestDayNumber(vector<vector<int>> oldNum);
vector<vector<int>> makeMinDateVector(vector<int> vec, vector<vector<string>> note);
vector<int> getTime(string time);
string calculateBest(int max, vector<int> vec, vector<vector<string>> note);
int countNote(vector<string> note);
void showByDayShort(vector<vector<string>> note, string temp);
int main()
{
// this vector is for all nots that save in vector of vector of string
vector<vector<string>> note;
// temp of each word in input
string sTemp, lineTemp = " ";
int state = 0;
int bigNoteLength;
// number of note
int noteCounter = -1;
while (!cin.eof())
{
state = 0;
getline(cin, lineTemp);
stringstream x(lineTemp);
while (x >> sTemp)
{
if (sTemp == "start_day")
{
// start to write new note
note.push_back(vector<string>());
noteCounter++;
}
else if (sTemp == "show_day")
{
state = 1;
x >> sTemp;
showByDay(note, sTemp);
}
else if (sTemp == "show_the_longest_day")
{
state = 1;
bigNoteLength = showLongestNote(note);
printShortNote(note, bigNoteLength);
}
else if (sTemp == "show_the_best_day")
{
state = 1;
BestDay(note);
}
else
{
note[noteCounter].push_back(sTemp);
}
}
if (!state)
{
note[noteCounter].push_back("\n");
}
}
return 0;
}
// return number of lingest note
int showLongestNote(vector<vector<string>> note)
{
int lengthTemp = 0;
int number = 0;
for (int i = 0; i < note.size(); i++)
{
if (lengthTemp < countNote(note[i]))
{
lengthTemp = countNote(note[i]);
number = i;
}
}
return number;
}
// show by day
void showByDay(vector<vector<string>> note, string temp)
{
for (int i = 0; i < note.size(); i++)
{
if (note[i][0] == temp)
{
printNote(note, i);
}
}
}
// for calculate best day
void BestDay(vector<vector<string>> note)
{
ifstream MyFile("positive-words.txt");
vector<string> files;
vector<int> listOfSum;
// for each word of file
string stemp;
int sum = 0;
int maxleter = 0;
int numberOfNote = 0;
while (MyFile.tellg() != (-1))
{
MyFile >> stemp;
files.push_back(stemp);
}
for (int i = note.size() - 1; i >= 0; i--)
{
sum = 0;
for (int j = 0; j < note[i].size(); j++)
{
for (int k = 0; k < files.size(); k++)
{
if (note[i][j] == files[k])
{
sum++;
}
}
}
listOfSum.push_back(sum);
if (maxleter <= sum)
{
maxleter = sum;
numberOfNote = i;
}
}
reverse(listOfSum.begin(), listOfSum.end());
stemp = calculateBest(maxleter, listOfSum, note);
showByDayShort(note, stemp);
}
// for print notes
void printNote(vector<vector<string>> note, int x)
{
for (int i = 2; i < note[x].size(); i++)
{
if (note[x][i] != "\n")
{
if (note[x][i+1]=="\n")
{
cout << note[x][i];
}
else{
cout << note[x][i] << " ";
}
}
else
{
cout << note[x][i];
}
}
}
// for print shorter of notes
void printShortNote(vector<vector<string>> note, int x)
{
int cnt = 0;
if (countNote(note[x]) > 20)
{
cout << note[x][0];
cout << note[x][1];
for (int i = 2; i < 21; i++)
{
if (note[x][i] != "\n")
{
for (auto x : note[x][i])
{
if (cnt < 20)
{
printf("%c", x);
cnt++;
}
else
{
break;
}
}
if (cnt >= 20)
{
break;
}
printf(" ");
cnt++;
}
else
{
for (auto x : note[x][i])
{
if (cnt < 20)
{
printf("%c", x);
cnt++;
}
else
{
break;
}
}
if (cnt >= 20)
{
break;
}
printf(" ");
cnt++;
}
}
cout << "..."
<< "\n";
}
else
{
cout << note[x][0];
cout << note[x][1];
for (int i = 2; i < note[x].size(); i++)
{
if (note[x][i] != "\n")
{
if (i==(note[x].size()-1))
{
cout << note[x][i];
}
else{
cout << note[x][i] << " ";
}
}
else
{
cout << note[x][i];
}
}
}
}
string calculateBest(int max, vector<int> vec, vector<vector<string>> note)
{
// vectro for list of numbers that has same name
vector<int> numOfVec;
int cnt = 0;
for (int i = 0; i < vec.size(); i++)
{
if (vec[i] == max)
{
cnt++;
numOfVec.push_back(i);
}
}
vector<vector<int>> vecto = makeMinDateVector(numOfVec, note);
return oldestDayNumber(vecto);
}
// make 2d vector of
vector<vector<int>> makeMinDateVector(vector<int> vec, vector<vector<string>> note)
{
vector<vector<int>> date;
for (int i = 0; i < vec.size(); i++)
{
date.push_back(spliteStringToInt(note[vec[i]][0]));
date[i].push_back(i); // for day // mounth // year // number of state
}
return date;
}
// for change each string to int to date as a vector of int ;
vector<int> spliteStringToInt(string time)
{
vector<int> times;
string year;
string month;
string day;
int cnt = 0;
stringstream t(time);
getline(t, day, '/');
getline(t, month, '/');
t >> year;
times.push_back(stoi(year));
times.push_back(stoi(month));
times.push_back(stoi(day));
return times;
}
// return i of oldest day
string oldestDayNumber(vector<vector<int>> oldNum)
{
string stemp;
sort(oldNum.begin(), oldNum.end());
stemp += to_string(oldNum[0][2]);
stemp += '/';
stemp += to_string(oldNum[0][1]);
stemp += '/';
stemp += to_string(oldNum[0][0]);
return stemp;
}
vector<int> getTime(string time)
{
vector<int> times;
string year;
string month;
string day;
int cnt = 0;
stringstream t(time);
getline(t, day, '/');
getline(t, month, '/');
t >> year;
times.push_back(stoi(year));
times.push_back(stoi(month));
times.push_back(stoi(day));
times.push_back(4);
return times;
}
// for count of each note
int countNote(vector<string> note)
{
int sum = 0;
for (auto x : note)
{
if (x != "\n")
{
sum += x.size();
sum++;
}
else
{
sum--;
}
}
return sum;
}
//for print short of it
void showByDayShort(vector<vector<string>> note, string temp)
{
for (int i = 0; i < note.size(); i++)
{
if (note[i][0] == temp)
{
printShortNote(note, i);
}
}
}

Xet Storage Details

Size:
8.38 kB
·
Xet hash:
0c5d9138fc6f468e7adc28f35a0d2e72e4c861ba2c24d2a28de6144ff6327526

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.