Advertisement
B1KMusic

99 botellas en espanol

Apr 13th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. /* This is a rough spanish language translation of 99 bottles: http://pastebin.com/Y2BWcRRQ
  2.  */
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #define VERSE_1 "%s botella%s de cerveza en la pared, %s botella%s de cerveza.\n"
  8. #define VERSE_2 "Tomar uno abajo, pasarlo alrededor, o, %s botella%s de cerveza en la pared.\n\n"
  9. #define VERSE_3 "No mas botellas de cerveza en la pared, no mas botellas de cerveza.\n"
  10. #define VERSE_4 "Ir a la tienda, comprar un poco mas, noventa y nueve botellas de cerveza en la pared.\n"
  11. #define SEPARATOR " y "
  12.  
  13. const char *ones_dict[] = {"no mas", "uno", "dos", "tres", "cuatro", "sinco", "seis", "siete", "ocho", "nueve"};
  14. const char *tens_dict[] = {0, 0, "veinta", "trenta", "cuarenta", "sincuenta", "seisenta", "setenta", "ochenta", "nueventa"};
  15. const char *teens_dict[] = {"diez", "onse", "dose", "trese", "catorse", "quinse", "diez y seis", "diez y siete", "diez y ocho", "diez y nueve"};
  16.  
  17. void to_english(char *buf, int bottles);
  18. int plural(int qty);
  19. void write_verse(int bottles);
  20.  
  21. void
  22. to_english(char *buf, int bottles)
  23. {/*{{{*/
  24.     int ones = bottles % 10,
  25.         tens = (bottles - ones) / 10;
  26.  
  27.     if(bottles == 0){
  28.         strncpy(buf, ones_dict[0], 30);
  29.     } else if(tens == 0){
  30.         strncpy(buf, ones_dict[ones], 30);
  31.     } else if(tens == 1){
  32.         strncpy(buf, teens_dict[ones], 30);
  33.     } else if(ones == 0){
  34.         strncpy(buf, tens_dict[tens], 30);
  35.     } else {
  36.         snprintf(buf, 30, "%s" SEPARATOR "%s", tens_dict[tens], ones_dict[ones]);
  37.     }
  38. }/*}}}*/
  39.  
  40. int
  41. plural(int qty)
  42. {/*{{{*/
  43.     return qty != 1;
  44. }/*}}}*/
  45.  
  46. void
  47. write_verse(int bottles)
  48. {/*{{{*/
  49.     char numbuf[30] = "";
  50.  
  51.     to_english(numbuf, bottles);
  52.     printf(VERSE_1, numbuf, plural(bottles) ? "s" : "", numbuf, plural(bottles) ? "s" : "");
  53.  
  54.     to_english(numbuf, bottles - 1);
  55.     printf(VERSE_2, numbuf, plural(bottles - 1) ? "s" : "");
  56.  
  57.     if(bottles - 1 == 0){
  58.         printf(VERSE_3 VERSE_4);
  59.     }
  60. }/*}}}*/
  61.  
  62. int
  63. main()
  64. {/*{{{*/
  65.     int bottles = 99;
  66.  
  67.     while(bottles){
  68.         write_verse(bottles);
  69.         bottles--;
  70.     }
  71. }/*}}}*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement