Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <assert.h>
- int conta(char c, char *s){
- int num_vezes=0;
- while(*s!='\0'){
- if(*s== '\t'){
- num_vezes++;
- }
- s++;
- }
- return num_vezes;
- }
- int ordenar(int vetorDeNumeros[]){
- int tamanhoVetor = (sizeof vetorDeNumeros)/(sizeof vetorDeNumeros[0]);
- int i;
- int j;
- int temp;
- for(i=0;i<tamanhoVetor;i++){
- for(j=0;j<tamanhoVetor;j++){
- if(vetorDeNumeros[i] < vetorDeNumeros[j]){
- temp = vetorDeNumeros[i];
- vetorDeNumeros[i] = vetorDeNumeros[j];
- vetorDeNumeros[j] = temp;
- }
- }
- }
- return vetorDeNumeros[0];
- }
- void clean(char * s){
- int i=0;
- while(s[i]!='\0'){
- if(s[i]=='\n'){
- s[i]='\0';
- }
- i++;
- }
- }
- void RemoveSpaces(char* source)
- {
- char* i = source;
- char* j = source;
- while(*j != 0)
- {
- *i = *j++;
- if(*i != ' ')
- i++;
- }
- *i = 0;
- }
- void cleanequal(char * s){
- int i=0;
- while(s[i]!='\0'){
- if(s[i]== '='){
- s[i]=' ';
- }
- i++;
- }
- }
- void append(char* s, char c)
- {
- int len = strlen(s);
- s[len] = c;
- s[len+1] = '\0';
- }
- char* expand_cell_references(const char* f, const char* const l, char* o); /*the magic engine*/
- const char* get_cell_value(const char* coordinate_b, const char* coordinate_e);
- const char* cells[][4] = {
- /* A B C D */
- { "the" , "lazy" , "cow" , "jumped" }, /* 1 */
- { "over" , "the" , "quick", "brown" }, /* 2 */
- { "paper", "packages", "tied" , "up" }, /* 3 */
- { "with" , "silver" , "white", "winters" }, /* 4 */
- { "that" , "melt" , "fox" , "springs" }, /* 5 */
- };
- const char* get_cell_value(const char* coordinate_b, const char* coordinate_e)
- {
- #ifdef DEBUG
- static const int maxrows = (sizeof(cells)/sizeof(*cells));
- static const int maxcols = (sizeof(cells[0])/sizeof(*cells[0]));
- #endif
- size_t col = 0, row = 0;
- const char* it;
- for (it=coordinate_b; it != coordinate_e; ++it)
- {
- if (*it >= 'A' && *it <= 'Z')
- col = 26*col + (*it - 'A');
- if (*it >= '0' && *it <= '9')
- row = 10*row + (*it - '0'); /* or use atoi and friends */
- }
- row--; /* 1-based row nums in Excel */
- #ifdef DEBUG
- assert(col>=0 && col < maxcols);
- assert(row>=0 && row < maxrows);
- #endif
- return cells[row][col]; /* 1-based indexes in Excel */
- }
- int main(){
- //int tamanho = 0;
- char vetor[302];
- int m;
- int k=0;
- int colunas = 0;
- int vetorDeNumeros[2];
- //localiza pelo numero maximo de coisas que ele vai ler
- char matris[30][26][302];
- //inicia-se o loop
- while(1){
- //Recebe os dados
- fgets(vetor, 302, stdin);
- //Verifica se tem a quebra de linha
- if(strcmp(vetor, "\n") == 0){
- break;
- }
- //Aqui eu insiro na funcao o vetor
- char *s = vetor;
- //Recebo a quantia de \t
- m = conta('\t', s);
- //Passo pra posicao do vetor, o numero de colunas
- vetorDeNumeros[k] = m+1;
- //Recebo o resultado do bubble sort
- colunas = ordenar(vetorDeNumeros);
- //faz a colocacao de cada elemento dentro de cada celula, tentei por funcao mas nao deu muito certo
- char *ponteiro;
- int j=0;
- while(j<colunas){
- ponteiro = strtok(vetor, "\t");
- while (ponteiro != NULL){
- strcpy(matris[k][j], ponteiro);
- ponteiro = strtok(NULL, "\t");
- //REMOVE OS \N DESNECESSARIOS
- clean(matris[k][j]);
- //REMOVE OS IGUAIS
- cleanequal((matris[k][j]));
- //REMOVE OS ESPAÇOS GERADOS PELOS ESPAÇOS
- RemoveSpaces(matris[k][j]);
- j++;
- }
- }
- //Quantia de linhas que foram
- k++;
- }
- int L = 0, linha=0;
- char col;
- int i, c;
- for(i = 0; i < k; i++){
- for(c = 0; c < colunas; c++){
- //printf("linha: %d coluna: %c >> |%s|", i, c, matris[i][c]);
- int line;
- int offset = 0, readCharCount;
- char op;
- char troca[301];
- char buffer[32];
- char out[1024] = {0};
- expand_cell_references(matris[i][c], matris[i][c]+strlen(matris[i][c]), out);
- puts(out); /* "The quick brown fox jumped over the lazy dog!" */
- // printf("%s\t", matris[i][c]);
- }
- printf("\n");
- }
- /*
- printf("%d lin, %d col\n\n", k, colunas);
- int w,z;
- for(w=0;w<k;w++){
- for(z=0;z<colunas;z++){
- printf("%s\t", matris[w][z]);
- }
- printf("\n");
- }
- */
- printf("\n");
- //system("pause");
- return 0;
- }
- char* expand_cell_references(const char* f, const char* const l, char* o)
- {
- enum parser_state {
- other,
- in_coord_col,
- in_coord_row
- } state = other;
- /*temporary storage for coordinates being parsed:*/
- char accum[16] = {0};
- char* accit = accum;
- while (f!=l)
- {
- switch(state) /*dummy, the transitions flow in fallthrough order for now*/
- {
- case other:
- *(accit = accum) = 0; /*reset the accumulator*/
- while (f!=l && !(*f>='A' && *f<='Z'))
- *o++ = *f++;
- /*fallthrough*/
- case in_coord_col:
- while (f!=l && *f>='A' && *f<='Z')
- *accit++ = *f++;
- /*fallthrough*/
- case in_coord_row:
- {
- const char* expanded = accum;
- if (f!=l && *f>='0' && *f<='9')
- {
- while (f!=l && *f>='0' && *f<='9')
- *accit++ = *f++;
- expanded = get_cell_value(accum, accit);
- }
- else
- {
- *accit = 0;
- }
- while (*expanded)
- *o++ = *expanded++;
- continue; /*state = other;*/
- }
- }
- }
- return o;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement