Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. struct Subject {
  8.   int score, year, semester;
  9.   string name;
  10.   vector<int> to;
  11.   int prof, id;
  12.   Subject(int _score = -1, int _year = -1, int _semester = -1,
  13.     string _name = "", vector<int> _to = {-1}){
  14.       score = _score;
  15.       year = _year;
  16.       semester = _semester;
  17.       name = _name;
  18.       to = _to;
  19.   }
  20. };
  21.  
  22. Subject T[35];
  23. vector<int> need[35];
  24.  
  25. int dfs(int v){
  26.   int prof = 0;
  27.   for(unsigned j = 0; j < T[v].to.size(); j++){
  28.     int w = T[v].to[j];
  29.     prof = max(prof, dfs(w) + 1);
  30.   }
  31.   return prof;
  32. }
  33.  
  34. bool by_prof(Subject a, Subject b){
  35.   if(a.prof == b.prof){
  36.     if(a.year == b.year){
  37.       return a.semester > b.semester;
  38.     }
  39.     return a.year > b.year;
  40.   }
  41.   return a.prof > b.prof;
  42. }
  43.  
  44. bool by_year(Subject a, Subject b){
  45.   if(a.year == b.year){
  46.     return a.semester < b.semester;
  47.   }
  48.   return a.year < b.year;
  49. }
  50.  
  51. void getCorrelativities(){
  52.   vector<Subject> S[35];
  53.   for(int i = 1; i <= 32; i++){
  54.     for(unsigned int j = 0; j < T[i].to.size(); j++){
  55.       S[ T[i].to[j] ].push_back( T[i] );
  56.     }
  57.   }
  58.   sort(T + 1, T + 33, by_year);
  59.   int last = 0;
  60.   int sem = 0;
  61.   for(int i = 1; i <= 32; i++){
  62.     int id = T[i].id;
  63.     if(T[i].year > last){
  64.       last = T[i].year;
  65.       sem = 0;
  66.       printf("Year: %d\n", last);
  67.     }
  68.     if(T[i].semester > sem){
  69.       sem = T[i].semester;
  70.       printf("    Semester: %d\n", sem);
  71.     }
  72.     printf("        %s:\n", T[i].name.c_str());
  73.     for(unsigned int j = 0; j < S[id].size(); j++){
  74.       printf("            -> %s\n", S[id][j].name.c_str());
  75.     }
  76.   }
  77. }
  78.  
  79. void getOrderBlock(){
  80.  
  81. }
  82.  
  83. int main(){
  84.   /* DATA */
  85.  
  86.   T[1]  = Subject(9,  1, 1, "Algebra y Geometria Analitica I", {4});
  87.   T[2]  = Subject(9,  1, 1, "Analisis Matematico I", {5});
  88.   T[3]  = Subject(10, 1, 1, "Programacion I", {6});
  89.   T[4]  = Subject(8,  1, 2, "Algebra y Geometria Analitica II", {7});
  90.   T[5]  = Subject(9,  1, 2, "Analisis Matematico II", {13, 14, 26});
  91.   T[6]  = Subject(9,  1, 2, "Programacion II", {8, 9, 12});
  92.  
  93.   T[7]  = Subject(-1, 2, 1, "Algebra Lineal", {10, 13, 26});
  94.   T[8]  = Subject(10, 2, 1, "Estructura de Datos y Algoritmos I", {10, 11, 15});
  95.   T[9]  = Subject(-1, 2, 1, "Lenguajes Formales y Computabilidad", {25});
  96.   T[10] = Subject(-1, 2, 2, "Complementos de Matematica I", {15});
  97.   T[11] = Subject(-1, 2, 2, "Arquitectura del Computador", {18, 19});
  98.   T[12] = Subject(-1, 2, 2, "Logica", {16, 20, 21, 23, 26});
  99.   T[13] = Subject(-1, 2, 2, "Metodos Numericos", {29, 30});
  100.  
  101.   T[14] = Subject(-1, 3, 1, "Probabilidad y Estadistica", {17});
  102.   T[15] = Subject(-1, 3, 1, "Estructuras de Datos y Algoritmos II", {16, 20, 21, 23, 25});
  103.   T[16] = Subject(-1, 3, 2, "Analisis de Lenguajes de Programacion", {25});
  104.   T[17] = Subject(-1, 3, 2, "Modelos Fisicos", {29, 30});
  105.   T[18] = Subject(-1, 3, 1, "Sistemas Operativos I", {22});
  106.   T[19] = Subject(-1, 3, 2, "Comunicaciones", {29, 30});
  107.   T[20] = Subject(-1, 3, 2, "Teoria de Bases de Datos", {23});
  108.   T[31] = Subject(8,  3, 2, "Ingles", {21, 22, 23, 25, 26, 29, 30});
  109.  
  110.   T[21] = Subject(-1, 4, 1, "Ingenieria del Software I", {24, 27});
  111.   T[22] = Subject(-1, 4, 1, "Sistemas Operativos II", {29, 30});
  112.   T[23] = Subject(-1, 4, 2, "Introduccion a la Inteligencia Artificial", {29, 30});
  113.   T[24] = Subject(-1, 4, 2, "Ingenieria del Software II", {32});
  114.   T[25] = Subject(-1, 4, 2, "Compiladores", {32});
  115.   T[26] = Subject(-1, 4, 2, "Complementos de Matematica II", {32});
  116.  
  117.   T[27] = Subject(-1, 5, 1, "Seguridad Informatica", {32});
  118.   T[28] = Subject(-1, 5, 2, "Optativa", {32});
  119.   T[29] = Subject(-1, 5, 1, "Practica Profesional", {32});
  120.   T[30] = Subject(-1, 5, 2, "Taller de Tesina", {32});
  121.   T[32] = Subject(-1, 5, 2, "Tesina", {});
  122.  
  123.   /* END OF DATA */
  124.  
  125.   for(int i = 1; i <= 32; i++){
  126.     T[i].id = i;
  127.     for(unsigned int j = 0; j < T[i].to.size(); j++){
  128.       need[ T[i].to[j] ].push_back(i);
  129.     }
  130.   }
  131.  
  132.   getCorrelativities();
  133.   getOrderBlock();
  134.  
  135.   printf("Aprobar una materia de grado i, significa que al menos faltan \
  136. unos i semestres para terminar\n\n");
  137.  
  138.   for(int i = 1; i <= 32; i++){
  139.     int d = dfs(i);
  140.     T[i].prof = d;
  141.     //~ printf("%2d: %50s: %d [%c]\n", i, T[i].name.c_str(), d, T[i].score >= 6 ? 'x' : ' ');
  142.   }
  143.  
  144.   sort(T + 1, T + 33, by_prof);
  145.   for(int i = 1; i <= 32; i++){
  146.     printf("%2d: %50s: %d [%c] : [", T[i].id, T[i].name.c_str(), T[i].prof, T[i].score >= 6 ? 'x' : ' ');
  147.     const vector<int> &V = need[ T[i].id ];
  148.     for(unsigned j = 0; j < V.size(); j++){
  149.       printf("%d", V[j]);
  150.       if(j + 1 < V.size()) printf(", ");
  151.     }
  152.     puts("]");  
  153.   }
  154.  
  155.   return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement