init
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
*.o
|
||||||
|
salida
|
||||||
|
salida.out
|
||||||
|
entrada.in
|
||||||
15
Makefile
Normal file
15
Makefile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
GPP = /usr/bin/g++
|
||||||
|
OPTS = -Wall -Wno-deprecated -std=c++17 -g
|
||||||
|
a.out: diccionariocuacs.o cuac.o fecha.o
|
||||||
|
$(GPP) $(OPTS) main.cpp diccionariocuacs.o cuac.o fecha.o
|
||||||
|
|
||||||
|
fecha.o: fecha.cpp fecha.hpp
|
||||||
|
$(GPP) $(OPTS) -c fecha.cpp
|
||||||
|
|
||||||
|
cuac.o: cuac.hpp cuac.cpp fecha.hpp
|
||||||
|
$(GPP) $(OPTS) -c cuac.cpp
|
||||||
|
|
||||||
|
diccionariocuacs.o: diccionariocuacs.hpp diccionariocuacs.cpp cuac.hpp fecha.hpp
|
||||||
|
$(GPP) $(OPTS) -c diccionariocuacs.cpp
|
||||||
|
|
||||||
|
|
||||||
43
cuac.cpp
Normal file
43
cuac.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include "cuac.hpp"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void Cuac::escribir() {
|
||||||
|
cout << usuario << " ";
|
||||||
|
fecha.escribir();
|
||||||
|
cout << "\n " << mensaje << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cuac::leer_mcuac() {
|
||||||
|
cin >> usuario;
|
||||||
|
fecha.leer();
|
||||||
|
cin.ignore();
|
||||||
|
getline(cin, mensaje);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cuac::leer_pcuac() {
|
||||||
|
int n;
|
||||||
|
cin >> usuario;
|
||||||
|
fecha.leer();
|
||||||
|
cin >> n;
|
||||||
|
mensaje = pcuac[n - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Cuac::comparar(Cuac &c) {
|
||||||
|
// false si es reciente o el mensaje u usuario es menor en orden lexicográfico
|
||||||
|
// true si es antiguo o el mensaje u usuario es mayor en orden lexicográfico
|
||||||
|
// ya ni lo sé
|
||||||
|
|
||||||
|
// true se usa como indicador de dónde insertar
|
||||||
|
if (fecha.es_menor(c.fecha)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (fecha.es_igual(c.fecha)) {
|
||||||
|
if (mensaje == c.mensaje) {
|
||||||
|
return !(usuario < c.usuario);
|
||||||
|
}
|
||||||
|
return !(mensaje < c.mensaje);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
50
cuac.hpp
Normal file
50
cuac.hpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "fecha.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
const string pcuac[30] = {"Afirmativo.",
|
||||||
|
"Negativo.",
|
||||||
|
"Estoy de viaje en el extranjero.",
|
||||||
|
"Muchas gracias a todos mis seguidores por vuestro apoyo.",
|
||||||
|
"Enhorabuena, campeones!", "Ver las novedades en mi pagina web.",
|
||||||
|
"Estad atentos a la gran exclusiva del siglo.",
|
||||||
|
"La inteligencia me persigue pero yo soy mas rapido.",
|
||||||
|
"Si no puedes convencerlos, confundelos.",
|
||||||
|
"La politica es el arte de crear problemas.",
|
||||||
|
"Donde estan las llaves, matarile, rile, rile...",
|
||||||
|
"Si no te gustan mis principios, puedo cambiarlos por otros.",
|
||||||
|
"Un dia lei que fumar era malo y deje de fumar.",
|
||||||
|
"Yo si se lo que es trabajar duro, de verdad, porque lo he visto por ahi.",
|
||||||
|
"Hay que trabajar ocho horas y dormir ocho horas, pero no las mismas.",
|
||||||
|
"Mi vida no es tan glamurosa como mi pagina web aparenta.",
|
||||||
|
"Todo tiempo pasado fue anterior.",
|
||||||
|
"El azucar no engorda... engorda el que se la toma.",
|
||||||
|
"Solo los genios somos modestos.",
|
||||||
|
"Nadie sabe escribir tambien como yo.",
|
||||||
|
"Si le molesta el mas alla, pongase mas aca.",
|
||||||
|
"Me gustaria ser valiente. Mi dentista asegura que no lo soy.",
|
||||||
|
"Si el dinero pudiera hablar, me diria adios.",
|
||||||
|
"Hoy me ha pasado una cosa tan increible que es mentira.",
|
||||||
|
"Si no tienes nada que hacer, por favor no lo hagas en clase.",
|
||||||
|
"Que nadie se vanaglorie de su justa y digna raza, que pudo ser un melon y salio una calabaza.",
|
||||||
|
"Me despido hasta la proxima. Buen viaje!",
|
||||||
|
"Cualquiera se puede equivocar, inclusivo yo.",
|
||||||
|
"Estoy en Egipto. Nunca habia visto las piramides tan solas.",
|
||||||
|
"El que quiera saber mas, que se vaya a Salamanca."
|
||||||
|
};
|
||||||
|
|
||||||
|
class Cuac {
|
||||||
|
private:
|
||||||
|
friend class DiccionarioCuacs;
|
||||||
|
string usuario;
|
||||||
|
Fecha fecha;
|
||||||
|
string mensaje;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void escribir();
|
||||||
|
void leer_pcuac();
|
||||||
|
void leer_mcuac();
|
||||||
|
bool comparar(Cuac &c); // falta implementar comparar!! ej. 004
|
||||||
|
};
|
||||||
65
diccionariocuacs.cpp
Normal file
65
diccionariocuacs.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include "diccionariocuacs.hpp"
|
||||||
|
|
||||||
|
DiccionarioCuacs::DiccionarioCuacs() {
|
||||||
|
contador = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiccionarioCuacs::insertar(Cuac nuevo) {
|
||||||
|
list<Cuac>::iterator it = lista.begin();
|
||||||
|
while (it != lista.end() && nuevo.comparar(*it)){
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
if (it==lista.end() || !nuevo.comparar(*it)) {
|
||||||
|
lista.insert(it--, nuevo);
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
contador++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiccionarioCuacs::last(int n){
|
||||||
|
cout << "last " << n << endl;
|
||||||
|
list<Cuac>::iterator it = lista.begin();
|
||||||
|
int i = 0;
|
||||||
|
while (it != lista.end() && n--) {
|
||||||
|
Cuac c = *it;
|
||||||
|
i++;
|
||||||
|
cout << i << ". ";
|
||||||
|
c.escribir();
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
cout << "Total: " << i << " cuac" << endl;
|
||||||
|
}
|
||||||
|
void DiccionarioCuacs::follow(string nombre){
|
||||||
|
cout << "follow " << nombre << endl;
|
||||||
|
list<Cuac>::iterator it;
|
||||||
|
int i = 0;
|
||||||
|
for (it = lista.begin(); it != lista.end(); it++) {
|
||||||
|
Cuac c = *it;
|
||||||
|
if (c.usuario == nombre) {
|
||||||
|
i++;
|
||||||
|
cout << i << ". ";
|
||||||
|
c.escribir();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << "Total: " << i << " cuac" << endl;
|
||||||
|
}
|
||||||
|
void DiccionarioCuacs::date(Fecha f1, Fecha f2){
|
||||||
|
cout << "date ";
|
||||||
|
f1.escribir();
|
||||||
|
cout << ' ';
|
||||||
|
f2.escribir();
|
||||||
|
cout << '\n';
|
||||||
|
int i = 0;
|
||||||
|
list<Cuac>::iterator it;
|
||||||
|
|
||||||
|
for (it = lista.begin(); it != lista.end(); it++) {
|
||||||
|
Cuac c = *it;
|
||||||
|
if ((f1.es_menor(c.fecha) && !f2.es_menor(c.fecha)) || f1.es_igual(c.fecha) || f2.es_igual(c.fecha)) {
|
||||||
|
i++;
|
||||||
|
cout << i << ". ";
|
||||||
|
c.escribir();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << "Total: " << i << " cuac" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
22
diccionariocuacs.hpp
Normal file
22
diccionariocuacs.hpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "fecha.hpp"
|
||||||
|
#include "cuac.hpp"
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DiccionarioCuacs {
|
||||||
|
private:
|
||||||
|
list<Cuac> lista;
|
||||||
|
int contador;
|
||||||
|
|
||||||
|
public:
|
||||||
|
DiccionarioCuacs();
|
||||||
|
void insertar(Cuac nuevo);
|
||||||
|
void last(int n);
|
||||||
|
void follow(string nombre);
|
||||||
|
void date(Fecha f1, Fecha f2);
|
||||||
|
int numElem() { return contador; }
|
||||||
|
};
|
||||||
|
|
||||||
55
fecha.cpp
Normal file
55
fecha.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include "fecha.hpp"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
Fecha::Fecha() {
|
||||||
|
d = 0;
|
||||||
|
m = 0;
|
||||||
|
a = 0;
|
||||||
|
h = 0;
|
||||||
|
m = 0;
|
||||||
|
s = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Fecha::leer() {
|
||||||
|
cin >> d;
|
||||||
|
cin.ignore();
|
||||||
|
cin >> m;
|
||||||
|
cin.ignore();
|
||||||
|
cin >> a;
|
||||||
|
|
||||||
|
cin >> h;
|
||||||
|
cin.ignore();
|
||||||
|
cin >> min;
|
||||||
|
cin.ignore();
|
||||||
|
cin >> s;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fecha::escribir() {
|
||||||
|
printf("%d/%d/%d %02d:%02d:%02d", d, m, a, h, min, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Fecha::es_igual(Fecha &f) {
|
||||||
|
if ((s == f.s) && (min == f.min) && (h == f.h) && (d == f.d) && (m == f.m) && (a == f.a)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Fecha::es_menor(Fecha &f) {
|
||||||
|
if (a != f.a) {
|
||||||
|
return a < f.a;
|
||||||
|
} else if (m != f.m) {
|
||||||
|
return m < f.m;
|
||||||
|
} else if (d != f.d) {
|
||||||
|
return d < f.d;
|
||||||
|
} else if (h != f.h) {
|
||||||
|
return h < f.h;
|
||||||
|
} else if (min != f.min) {
|
||||||
|
return min < f.min;
|
||||||
|
} else {
|
||||||
|
return s < f.s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
15
fecha.hpp
Normal file
15
fecha.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
class Fecha {
|
||||||
|
public:
|
||||||
|
Fecha();
|
||||||
|
bool leer();
|
||||||
|
void escribir();
|
||||||
|
bool es_igual(Fecha &f);
|
||||||
|
bool es_menor(Fecha &f);
|
||||||
|
private:
|
||||||
|
int d, m, a;
|
||||||
|
int h, min, s;
|
||||||
|
};
|
||||||
|
|
||||||
66
main.cpp
Normal file
66
main.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include "fecha.hpp"
|
||||||
|
#include "cuac.hpp"
|
||||||
|
#include "diccionariocuacs.hpp"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
DiccionarioCuacs dic;
|
||||||
|
|
||||||
|
void procesar_pcuac() {
|
||||||
|
Cuac nuevo;
|
||||||
|
nuevo.leer_pcuac();
|
||||||
|
dic.insertar(nuevo);
|
||||||
|
cout << dic.numElem() << " cuac" << endl;;
|
||||||
|
}
|
||||||
|
|
||||||
|
void procesar_mcuac() {
|
||||||
|
Cuac nuevo;
|
||||||
|
nuevo.leer_mcuac();
|
||||||
|
dic.insertar(nuevo);
|
||||||
|
cout << dic.numElem() << " cuac" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void procesar_follow() {
|
||||||
|
string nombre;
|
||||||
|
cin >> nombre;
|
||||||
|
dic.follow(nombre); // follow muestra los mensajes del usuario <nombre>
|
||||||
|
}
|
||||||
|
|
||||||
|
void procesar_last() {
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
dic.last(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void procesar_date() {
|
||||||
|
Fecha f1, f2;
|
||||||
|
f1.leer();
|
||||||
|
f2.leer();
|
||||||
|
dic.date(f1, f2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int cuacs = 1;
|
||||||
|
string comando;
|
||||||
|
while (cin >> comando) {
|
||||||
|
if (comando == "pcuac") {
|
||||||
|
procesar_pcuac();
|
||||||
|
cuacs++;
|
||||||
|
} else if (comando == "mcuac") {
|
||||||
|
procesar_mcuac();
|
||||||
|
cuacs++;
|
||||||
|
} else if (comando == "last") {
|
||||||
|
procesar_last();
|
||||||
|
} else if (comando == "follow") {
|
||||||
|
procesar_follow();
|
||||||
|
} else if (comando == "date") {
|
||||||
|
procesar_date();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user