/home/toolbox/public_html/solutions/116/11679/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: 2021-12-7
19 * Purpose: fun
20 * Problem: 11679 - Sub-prime
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 #define MAX_BANKS 25
28
29 int banks[MAX_BANKS];
30 int bankCnt;
31 int debCnt;
32
33 void init()
34 {
35 /* FUNCTION init */
36 } /* FUNCTION init */
37
38 void dump()
39 {
40 /* FUNCTION dump */
41 } /* FUNCTION dump */
42
43 int getInput()
44 {
45 /* FUNCTION getInput */
46 int dataReadFlag;
47 int i;
48
49 scanf(" %d %d ", &bankCnt, &debCnt);
50 dataReadFlag = (0 != bankCnt) || (0 != debCnt);
51 if (dataReadFlag)
52 {
53 /* load bank initial balance */
54 bankCnt++;
55 for (i=1; bankCnt>i; i++)
56 {
57 /* for each bank */
58 scanf(" %d ", &banks[i]);
59 } /* for each bank */
60 } /* load bank initial balance */
61 return (dataReadFlag);
62 } /* FUNCTION getInput */
63
64 void process()
65 {
66 /* FUNCTION process */
67 int bankTo;
68 int bankFrom;
69 int amount;
70 int i;
71 int okay = TRUE;
72
73 for (i=0; debCnt>i; i++)
74 {
75 /* for each debt */
76 scanf(" %d %d %d ", &bankFrom, &bankTo, &amount);
77 banks[bankTo] = banks[bankTo] + amount;
78 banks[bankFrom] = banks[bankFrom] - amount;
79 } /* for each debt */
80 for (i=1; bankCnt>i; i++)
81 {
82 /* check each bank */
83 DEBUG printf("bank[%d] %d\n", i, banks[i]);
84 okay = okay && (0 <= banks[i]);
85 } /* check each bank */
86 if (okay)
87 {
88 printf("S\n");
89 }
90 else
91 {
92 printf("N\n");
93 }
94 } /* FUNCTION process */
95
96 int main()
97 {
98 /* main */
99 int moreToDo;
100
101 init();
102 moreToDo = getInput();
103 while (moreToDo)
104 {
105 /* while */
106 process();
107 moreToDo = getInput();
108 } /* while */
109
110 return EXIT_SUCCESS;
111 } /* main */
112