Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. /*
  2.  * main.c
  3.  *
  4.  *  Created on: 10.2.2012
  5.  *      Author: Morphe
  6.  */
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <locale.h>
  10.  
  11. char *numbers[] = {
  12.         "ноль", "один", "дв", "три", "четыр", "пят", "шест", "сем", "восем",
  13.         "девят", "ьдесят", "енадцать", "сорок", "девяносто"
  14. }, *minus="минус";
  15.  
  16. char *getBody(int x) {
  17.     if(x>=20) {
  18.         x/=10;
  19.         if(x==4) return numbers[12];
  20.         else if(x==9) return numbers[13];
  21.     }
  22.     else if(x>10) x-=10;
  23.     else if(x==10) return numbers[10]+1;
  24.  
  25.     return numbers[x];
  26. }
  27.  
  28. char *getSuffix(int x) {
  29.     if(x>=90)
  30.         return "";
  31.     else if(x>=50)
  32.         return numbers[10]+(x/10==7 ? 1 : 0);
  33.     else if(x>=40)
  34.         return "";
  35.     else if(x>=30)
  36.         return numbers[11]+3;
  37.     else if(x>=20)
  38.         return numbers[11]+2;
  39.     else if(x>11)
  40.         return numbers[11]+(x>12?1:0);
  41.     else if(x>=5)
  42.         return "ь";
  43.     switch (x) {
  44.     case 2:
  45.         return "a";
  46.     case 4:
  47.         return "е";
  48.     default:
  49.         break;
  50.     }
  51.     return "";
  52. }
  53.  
  54. int main() {
  55.     int x;
  56.     setlocale(LC_ALL, "Russian");
  57.     while(1) {
  58.         scanf("%d", &x);
  59.         printf("%s%s", getBody(x), getSuffix(x));
  60.         if(x>=20) {
  61.             x%=10;
  62.             if(x!=0) printf(" %s%s", getBody(x), getSuffix(x));
  63.         }
  64.         putchar('\n');
  65.         system("pause");
  66.     }
  67.     return 0;
  68. }
Add Comment
Please, Sign In to add comment