Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <algorithm>
- #include <iterator>
- #include <vector>
- #include <fstream>
- using namespace std;
- //Metodo para agarrar el nombre del archivo donde estan las oraciones
- string getNameFile(){
- string sFileName;
- cout << "Place name of the file to process: ";
- cin >> sFileName;
- return sFileName;
- }
- //Metodo para llenar un vector con las oraciones del archivo
- vector<string> getinput(string sFileName){
- vector<string> input;
- string sentence;
- ifstream file(sFileName);
- while(getline(file, sentence)){ //Agarrar cada oracion y guardarla en un vector
- input.push_back(sentence);
- }
- return input;
- }
- //Metodo en donde recibe un arreglo de strings y hace todo los desplazamientos circulares para cada string
- vector<string> Solve(vector<string> input){
- vector<string> sol;
- for(int iA=0;iA<input.size();iA++){
- vector<string> phrase; //vector que contenera cada palabra de una oracion
- istringstream iss(input[iA]);
- do
- {
- string subs;
- iss >> subs;
- phrase.push_back(subs);
- } while (iss); //Loop para meter cada palabra de la oracion dentro de un vector
- string extra;
- for (int i=0; i < phrase.size()-1; i++){//Loop para iterar en todas las palabras
- extra = "";
- for (int j=0; j < phrase.size(); j++){//Hacer un circular shift dependiendo de la iteracion que es
- if (j == phrase.size()-1){
- extra = extra + phrase[(i+j)%phrase.size()];
- } else if (j == 0){
- extra = extra + phrase[(i+j)%phrase.size()] + " ";
- } else {
- extra = extra + phrase[(i+j)%phrase.size()] + " ";
- }
- }
- sol.push_back(extra);
- }
- phrase.clear();
- }
- return sol;
- }
- //Modifica todas las oraciones a ser lowercase
- void lowerCases(vector<string> &input){
- for (int i=0; i < input.size(); i++){
- 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
- }
- }
- //Imprime todas las desplazamientos circulares
- void print(vector<string> &answer){
- for (int i=0; i < answer.size(); i++){
- cout << answer[i] << endl;
- }
- }
- int main(){
- vector<string> input;
- vector<string> answer;
- string NameFile;
- NameFile = getNameFile();
- input = getinput(NameFile);
- lowerCases(input);
- answer = Solve(input);
- sort(answer.begin(), answer.end());
- print(answer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement