Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <vector>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. //Metodo para agarrar el nombre del archivo donde estan las oraciones
  12. string getNameFile(){
  13.     string sFileName;
  14.     cout << "Place name of the file to process: ";
  15.     cin >> sFileName;
  16.     return sFileName;
  17. }
  18.  
  19. //Metodo para llenar un vector con las oraciones del archivo
  20. vector<string> getinput(string sFileName){
  21.   vector<string> input;
  22.   string sentence;
  23.   ifstream file(sFileName);
  24.   while(getline(file, sentence)){ //Agarrar cada oracion y guardarla en un vector
  25.     input.push_back(sentence);
  26.   }
  27.   return input;
  28. }
  29.  
  30. //Metodo en donde recibe un arreglo de strings y hace todo los desplazamientos circulares para cada string
  31. vector<string> Solve(vector<string> input){
  32.   vector<string> sol;
  33.   for(int iA=0;iA<input.size();iA++){
  34.     vector<string> phrase; //vector que contenera cada palabra de una oracion
  35.     istringstream iss(input[iA]);
  36.     do
  37.     {
  38.         string subs;
  39.         iss >> subs;
  40.         phrase.push_back(subs);
  41.     } while (iss); //Loop para meter cada palabra de la oracion dentro de un vector
  42.     string extra;
  43.     for (int i=0; i < phrase.size()-1; i++){//Loop para iterar en todas las palabras
  44.       extra = "";
  45.       for (int j=0; j < phrase.size(); j++){//Hacer un circular shift dependiendo de la iteracion que es
  46.         if (j == phrase.size()-1){
  47.           extra = extra + phrase[(i+j)%phrase.size()];
  48.         } else if (j == 0){
  49.           extra = extra + phrase[(i+j)%phrase.size()] + " ";
  50.         } else {
  51.           extra = extra + phrase[(i+j)%phrase.size()] + " ";
  52.         }
  53.       }
  54.       sol.push_back(extra);
  55.     }
  56.     phrase.clear();
  57.   }
  58.   return sol;
  59. }
  60.  
  61. //Modifica todas las oraciones a ser lowercase
  62. void lowerCases(vector<string> &input){
  63.   for (int i=0; i < input.size(); i++){
  64.     transform(input[i].begin(), input[i].end(), input[i].begin(), ::tolower); //Transform modifica todo un arreglo desde el princirpio al fin dado un metodo de modificacion
  65.   }
  66. }
  67.  
  68. //Imprime todas las desplazamientos circulares
  69. void print(vector<string> &answer){
  70.   for (int i=0; i < answer.size(); i++){
  71.     cout << answer[i] << endl;
  72.   }
  73. }
  74.  
  75. int main(){
  76.   vector<string> input;
  77.   vector<string> answer;
  78.   string NameFile;
  79.   NameFile = getNameFile();
  80.   input = getinput(NameFile);
  81.   lowerCases(input);
  82.   answer = Solve(input);
  83.   sort(answer.begin(), answer.end());
  84.   print(answer);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement