Solução: Problema da cifra no DNA (Paulo Cesar)

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int get_dna_value( char type )
{
  switch(type)
  {
    case 'A':
      return 0;
    case 'C':
      return 1;
    case 'G':
      return 2;
    case 'T':
      return 3;
  }
}
 
int get_char_value( char * str)
{
  int value = get_dna_value(str[0])*16 + get_dna_value(str[1])*4 +
          get_dna_value(str[2]);
  value+=65;
  if(value < 'A' || value > 'Z')
    return 32;
  else
    return value;
}
 
int main()
{
  char str[202];
  scanf("%s",str);
  while(str[0]!='0')
  {
    int cont;
    for(cont = 0; cont < strlen(str);  cont+=3)
    {
      char word[3];
      word[0] = str[cont];
      word[1] = str[cont+1];
      word[2] = str[cont+2];
      printf("%c",get_char_value(word));
    }
    printf("\n");
    scanf("%s",str);
  }
  return 0;
}