Advertisement
Guest User

Untitled

a guest
Sep 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. inline int tamanho(char string[]);
  7. inline void reverso(char stringrev[]);
  8.  
  9. int main(void){
  10.    
  11.     int cont, aux = 0, i = 0, i2 = 0;
  12.     char frase[255], novafrase[255];
  13.    
  14.     cin >> cont;
  15.     cin.ignore();
  16.     for(cont; cont > 0 ;cont--){
  17.        
  18.         fgets(frase, 255, stdin);
  19.         fflush(stdin);
  20.         i = 0;
  21.         i2 = 0;
  22.        
  23.         while(frase[i] != '\0'){
  24.            
  25.             if(frase[i] != ' '){
  26.                 novafrase[i2] = frase[i];
  27.                 i2++;
  28.             }
  29.            
  30.             i++;
  31.         }
  32.        
  33.         aux = tamanho(novafrase);
  34.        
  35.         cout << endl << aux << endl;
  36.        
  37.         reverso(novafrase);
  38.        
  39.     }
  40.    
  41. }
  42.  
  43. inline int tamanho(char string[]){
  44.    
  45.     int i = 0;
  46.     i = 0;
  47.     while(string[i] != '\0'){
  48.        
  49.         i++;
  50.        
  51.     }
  52.     i--;
  53.     i--;
  54.    
  55.     return i;
  56.    
  57. }
  58.  
  59.  
  60.  
  61. inline void reverso(char string2[]){
  62.    
  63.     int j = 0, i = 0, aux = 0;
  64.     char fraserev[255];
  65.    
  66.     j = tamanho(string2);
  67.     aux = j;
  68.     for(aux, i = 0; aux > 0; aux--, i++){
  69.        
  70.         fraserev[aux] = string2[i];
  71.        
  72.     }
  73.     aux = j;
  74.     int count = 0, i2 = 1;
  75.    
  76.     for(i = 0, i2 = 1; i < aux, i2 <= aux; i++, i2++){
  77.        
  78.         if(string2[i] == fraserev[i2]){
  79.             count++;
  80.         }
  81.         printf("%c - %c\n", string2[i], fraserev[i2]);
  82.     }
  83.     if(count == j){
  84.         printf("\nSIM\n");
  85.     }else{
  86.         printf("\nNAO\n");
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement