Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * File: main.cpp
- * Author: alulab14
- *
- * Created on 13 de mayo de 2017, 02:25 PM
- */
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #define INC 5
- using namespace std;
- /*
- *
- */
- void generarLetras(char *&letras,char *&letrasmin){
- char auxletras[100];
- char auxletrasmin[100];
- char linea[6];
- int nletras=26;
- for(int i=0;i<26;i++){
- auxletras[i]='A'+i;
- auxletrasmin[i]='a'+i;
- }
- while(cin.getline(linea,5) and (strlen(linea)!=0)){
- auxletras[nletras]=linea[0];
- auxletrasmin[nletras]=linea[3];
- nletras++;
- }
- letras=new char[nletras+1];
- letrasmin=new char[nletras+1];
- for(int i=0;i<nletras;i++){
- letras[i]=auxletras[i];
- letrasmin[i]=auxletrasmin[i];
- }
- letras[nletras]='\0';
- letrasmin[nletras]='\0';
- }
- void memExacta_str(char**input,char**&output,int numElem){
- output=new char*[numElem+1];
- for(int i=0;i<numElem;i++){
- int size=strlen(input[i])+1;
- output[i]=new char[size];
- strcpy(output[i],input[i]);
- }
- output[numElem]=NULL;
- }
- void split_Tokens(char* linea, char ** & palabras, int n){
- int numPal = 0;
- char *auxPal[500];
- if(!isblank(linea[0])){
- auxPal[numPal] = linea;
- numPal++;
- }
- for(int i = 1; linea[i] != '\0'; i++){
- if(!isblank(linea[i]) and (isblank(linea[i-1]) or (linea[i-1] == '\0')) ){
- auxPal[numPal] = &linea[i];
- numPal++;
- }
- if(isblank(linea[i]) and !isblank(linea[i-1]) ){
- linea[i] = '\0';
- }
- if(numPal == n) break;
- }
- memExacta_str(auxPal,palabras,numPal);
- }
- void a_mayus(char *word,char *letras,char *letrasmin){
- bool encontrado;
- cout<<word<<endl;
- for(int i=0;i<strlen(word);i++){
- encontrado=0;
- for(int j=0;j<strlen(letras);j++){
- if(word[i]==letras[j]){
- encontrado=1;
- break;
- }
- }
- if (encontrado) continue;
- for(int j=0;j<strlen(letras);j++){
- if(word[i]==letrasmin[j]){
- word[i]=letras[j];
- break;
- }
- }
- }
- cout<<word<<endl;
- }
- template <typename T>
- void incrementarNum(T *&lst,int numElem){
- if(lst==NULL){
- lst=new T[INC+1];
- for(int i=0;i<INC;i++) lst[i]=-1;
- }
- else{
- T *lstAux=new T[numElem+INC+1];
- for(int i=0;i<numElem;i++) lstAux[i]=lst[i];
- for(int i=numElem;i<=numElem+INC;i++) lstAux[i]=-1;
- delete []lst;
- lst=lstAux;
- }
- }
- template <typename T>
- void agregarNum(T *&lst,T elem){
- if(lst==NULL){
- incrementarNum(lst,0);
- lst[0]=elem;
- for(int i=0;i<INC;i++) lst[i]=-1;
- }
- else{
- int numElem=0;
- for(int i=0;lst[numElem]!=-1;i++){
- numElem++;
- }
- if(numElem%INC==0) {incrementarNum(lst,numElem);}
- lst[numElem]=elem;
- }
- }
- void incrementar(char **&lst,int numElem){
- if(lst==NULL){
- lst=new char*[INC+1];
- for(int i=0;i<INC;i++) lst[i]=NULL;
- }
- else{
- char **lstAux=new char *[numElem+INC+1];
- for(int i=0;i<numElem;i++) lstAux[i]=lst[i];
- for(int i=numElem;i<=numElem+INC;i++) lstAux[i]=NULL;
- delete []lst;
- lst=lstAux;
- }
- }
- void agregarPalabra(char**&lst,char *elem){
- cout<<"Vamos a agregar "<<elem<<endl;
- if(lst==NULL){
- cout<<"Nulo: "<<elem<<endl;
- incrementar(lst,0);
- lst[0]=elem;
- }
- else{
- int numElem=0,idx=0;
- for(int i=0;lst[numElem];i++){
- if(strcmp(lst[numElem],elem)==0) return;
- if(strcmp(lst[numElem],elem)<0) idx++;
- numElem++;
- }
- if(numElem%INC==0) incrementar(lst,numElem);
- for(int i=numElem;i>=idx;i--)
- lst[i]=lst[i-1];
- lst[idx]=elem;
- }
- {
- char ***tweets;
- tweets = new char**[6];
- }
- }
- void agregarDic(char ***&palabras,char *word,char *letras,char *letrasmin,int *&valoresEnteros,double *&valoresDePuntoFlotante){
- //Si es palabra
- if(!isdigit(word[0])){
- //Es palabra
- a_mayus(word,letras,letrasmin);
- //Si comienza con letra normal
- if(word[0]>='A' and word[0]<='Z'){
- cout<<"Agregar en indice: "<<word[0]-'A'<<endl;
- agregarPalabra(palabras[word[0]-'A'],word);
- }
- else{
- //Si comienza con letra especial
- for(int i=26;i<strlen(letras);i++)
- if(letras[i]==word[0]){
- agregarPalabra(palabras[i],word);
- break;
- }
- }
- //cout << "LA WORD YA PROCESADA = " << word << endl;
- return;
- }
- //Veamos si es float
- bool isFloat=0;
- for(int i=0;i<strlen(word);i++)
- if(word[i]=='.') isFloat=1;
- if(isFloat)
- agregarNum(valoresDePuntoFlotante,atof(word));
- else
- agregarNum(valoresEnteros,atoi(word));
- }
- void leerPalabras(char *letras,char *letrasmin,char ***&palabras,int *&valoresEnteros,double *&valoresDePuntoFlotante){
- valoresEnteros=NULL;
- valoresDePuntoFlotante=NULL;
- int nletras=strlen(letras);
- palabras=new char**[nletras+1];
- for(int i=0;i<nletras+1;i++) palabras[i]=NULL;
- char linea[400];
- while(cin.getline(linea,390)){
- cout<<"LA LINEA: "<<linea<<endl;
- char **words;
- split_Tokens(linea,words,-1);
- for(int i=0;words[i]!=NULL;i++){
- cout<< "La word a analizar es : " << words[i] << endl;
- agregarDic(palabras,words[i],letras,letrasmin,valoresEnteros,valoresDePuntoFlotante);
- }
- delete []palabras;
- }
- }
- void crearDiccionario(char *&letras,char ***&palabras,int *valoresEnteros,double *valoresDePuntoFlotante){
- char *letrasmin;
- generarLetras(letras,letrasmin);
- leerPalabras(letras,letrasmin,palabras,valoresEnteros,valoresDePuntoFlotante);
- }
- int main(int argc, char** argv) {
- char *letras,***palabras;
- int *valoresEnteros;
- double *valoresDePuntoFlotante;
- crearDiccionario(letras,palabras,valoresEnteros,valoresDePuntoFlotante);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment