/home/toolbox/public_html/solutions/111/11185/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2023-02-14
19 * Purpose: fun
20 * Problem: 11185 - Ternary
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 #define MAX_CHARS 100
28
29 int num;
30 char n3[MAX_CHARS];
31
32 void init()
33 {
34 /* FUNCTION init */
35 } /* FUNCTION init */
36
37 void dump()
38 {
39 /* FUNCTION dump */
40 } /* FUNCTION dump */
41
42 int getInput()
43 {
44 /* FUNCTION getInput */
45 int dataReadFlag;
46
47 scanf(" %d ", &num);
48 dataReadFlag = 0 <= num;
49 return (dataReadFlag);
50 } /* FUNCTION getInput */
51
52 void process()
53 {
54 /* FUNCTION process */
55 int cnt = 0;
56 int tmp;
57 int i;
58
59
60 if (0 == num)
61 {
62 /* 0 wa input */
63 cnt = 1;
64 n3[0] = '0';
65 } /* 0 wa input */
66 else
67 while (0 < num)
68 {
69 /* while */
70 tmp = num % 3;
71 n3[cnt] = '0' + tmp;
72 cnt++;
73 num = num / 3;
74 } /* while */
75
76 for (i=(cnt-1); 0<=i; i--)
77 {
78 /* for */
79 printf("%c", n3[i]);
80 } /* for */
81 printf("\n");
82
83
84 } /* FUNCTION process */
85
86 int main()
87 {
88 /* main */
89 int moreToDo;
90
91 moreToDo = getInput();
92 while (moreToDo)
93 {
94 /* while */
95 process();
96 moreToDo = getInput();
97 } /* while */
98
99 return EXIT_SUCCESS;
100 } /* main */
101