Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- struct stack{
- char vet[200];
- int top;
- }typedef node;
- void iniciar(node *p) {
- p->top=-1;
- }
- void push(node *p,char x){
- if (p->top==199) printf("Maximo de caracteres.\n");
- else{
- p->top++;
- p->vet[p->top]=x;
- }
- }
- char pop(node *p){
- char x;
- if(p->top==-1)return 0;
- x=p->vet[p->top];
- p->top--;
- return x;
- }
- void inverte(char fr[],node *p){
- int i=0,cont=0,k=0,j=0,x=0;
- char aux[200];
- while(fr[i]!='\0'){
- if(fr[i]==' '||i==0)cont++;
- i++;
- }
- cont/=2;
- if(cont%2==1)cont++;
- i=0;
- while(cont--){
- while(fr[i]!='\0'&&fr[i]!=' '&&fr[i]!=','){
- push(p,fr[i]);
- i++;
- }
- if(fr[i]==','){
- aux[k]=fr[i];
- k++;
- i++;
- }
- aux[k]=fr[i];
- k++;
- i++;
- while(fr[i]!='\0'&&fr[i]!=' '){
- aux[k]=fr[i];
- k++;
- i++;
- }
- aux[k]=fr[i];
- k++;
- i++;
- aux[k]='\0';
- while(p->top!=-1){
- fr[j]=pop(p);
- j++;
- }
- while(aux[x]!='\0'){
- fr[j]=aux[x];
- x++;
- j++;
- }
- }
- }
- int main(){
- node pilha;
- iniciar(&pilha);
- char pa[200];
- gets(pa);
- inverte(pa,&pilha);
- puts(pa);
- //HOJE O SOL ESTA LINDO, ILUMINANDO NOSSAS VIDAS
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement