Solução: Problema da palavra mágica (Mauricio Lage)

From AdonaiMedrado.Pro.Br
Revision as of 16:52, 3 July 2009 by 200.17.147.2 (Talk) (New page: #include <stdio.h> #include <stdlib.h> #include <string.h> int crescente(const void *a, const void *b) { return *(char *)a-*(char *)b; } int main(int argc, char** argv) { char...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. include <stdio.h>
  2. include <stdlib.h>
  3. include <string.h>

int crescente(const void *a, const void *b) { return *(char *)a-*(char *)b; }


int main(int argc, char** argv) {

   char palavra[101];
   char prefixo[51]= "";
   char sufixo[51]= "";
   int tamPalavra;
   
   scanf("%s", palavra);
   tamPalavra= strlen(palavra);
   if( (tamPalavra % 2) == 0 ) {
       strncat(prefixo, palavra, tamPalavra/2);
       strncat(sufixo, &palavra[tamPalavra/2], tamPalavra/2);                
       qsort(prefixo, (tamPalavra / 2), sizeof(char), crescente);        
       if(!strcmp(prefixo, sufixo)) {
           printf("%c\n", 'S');
       }
       else {
           printf("%c\n", 'N');            
       }
       
   }
   else {
       printf("%c\n", 'N');
   }
   
   
   return (EXIT_SUCCESS);

}