Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(){
  5.     char vetor_unidades[10][10] = {
  6.         "zero",
  7.         "um",
  8.         "dois",
  9.         "tres",
  10.         "quatro",
  11.         "cinco",
  12.         "seis",
  13.         "sete",
  14.         "oito",
  15.         "nove"
  16.     };
  17.  
  18.     char vetor_dez_dnove[10][10] = {
  19.         "dez",
  20.         "onze",
  21.         "doze",
  22.         "treze",
  23.         "quatorze",
  24.         "quinze",
  25.         "dezesseis",
  26.         "dezesete",
  27.         "dezoito",
  28.         "dezenove",
  29.     };
  30.  
  31.     char vetor_dezenas[10][10] = {
  32.         "vinte",
  33.         "trinta",
  34.         "quarenta",
  35.         "cinquenta",
  36.         "sessenta",
  37.         "setenta",
  38.         "oitenta",
  39.         "noventa"
  40.     };
  41.  
  42.     char vetor_centena[15][15] = {
  43.         "cem",
  44.         "cento",
  45.         "duzentos",
  46.         "trezentos",
  47.         "quatrocentos",
  48.         "quinhentos",
  49.         "seiscentos",
  50.         "setecentos",
  51.         "oitocentos",
  52.         "novecentos",
  53.     };
  54.     char numero[100];
  55.     fgets(numero, 100, stdin);
  56.     int i, j, num=0, k=0;
  57.     for(i=0;i<10;i++){
  58.         int aux=0;
  59.         for(j=0;j<strlen(vetor_centena[i]); j++){
  60.             if(numero[j]!=vetor_centena[i][j]){
  61.                 aux++;
  62.             }
  63.             else if(j==strlen(vetor_centena[i])-1&&aux==0){
  64.                 k=strlen(vetor_centena[i])+3;
  65.                 if(i==0){
  66.                     i++;
  67.                 }
  68.                 num=(i)*100;
  69.  
  70.             }
  71.         }
  72.  
  73.  
  74.     }
  75.         for(i=0;i<8;i++){
  76.             int aux=0, x;
  77.             for(j=0, x=k;j<strlen(vetor_dezenas[i]); j++, x++){
  78.                 if(numero[x]!=vetor_dezenas[i][j]){
  79.                     aux++;
  80.                 }
  81.                 else if(j==strlen(vetor_dezenas[i])-1&&aux==0){
  82.                     k=k+ (strlen (vetor_dezenas[i])+3);
  83.                     num=num+((i+2)*10);
  84.  
  85.             }
  86.         }
  87. }
  88.         for(i=0;i<10;i++){
  89.         int aux=0, y;
  90.            for(j=0, y=k; j<strlen(vetor_unidades[i]);j++,y++){
  91.             if(numero[y]!=vetor_unidades[i][j]){
  92.                 aux++;
  93.             }
  94.             else if (j==strlen(vetor_unidades[i])-1&&aux==0){
  95.                 num=num+i;
  96.             }}}
  97.     for(i=0;i<10;i++){
  98.         int aux=0, z;
  99.        for(j=0, z=k; j<strlen(vetor_dez_dnove[i]);j++,z++){
  100.         if(numero[z]!=vetor_dez_dnove[i][j]){
  101.             aux++;
  102.         }
  103.         else if (j==strlen(vetor_dez_dnove[i])-1&&aux==0){
  104.             if(i>5){
  105.                num=num-10;
  106.             }
  107.             num=num+(10+i) ;
  108.         }}}
  109.     printf("%i", num);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement