# 50007. Yard, Foot, and Inch

## Problem description

Write a program to manage length. A length has three components -- yard, foot, and inch. A yard is 3 feet and a foot is 12 inches. We will use an array of length 3 to present a length. length will be the yard, length will be the foot, and length will be the inch. All of them are non-negative integers. Now you need to implement the following three functions.

1. void init(int length); This function resets the length to 0.
2. void add(int length, int i); This function adds i inches to length. Note that the final length should have inch between 0 and 11, and foot between 0 and 2.
3. void sum(int lengtha, int lengthb, int lengthc); This function adds lengtha and lengthb and place the sum into lengthc. Note that the lengthc should have inch between 0 and 11, and foot between 0 and 2.
4. void diff(int lengtha, int lengthb, int lengthc); This function subtract lengthb from lengtha and place the different into lengthc. We guarantee that lengtha is no less than lessb. Note that the lengthc should have inch between 0 and 11, and foot between 0 and 2.

• 10 pt. Implement only init.
• 30 pt. Implement only init and add.
• 30 pt. Implement the first three functions.
• 30 pt. Implement all four functions.

### length.h

1234void init(int length);void add(int length, int i);void sum(int lengtha, int lengthb, int lengthc);void diff(int lengtha, int lengthb, int lengthc);


### length.c

123456789101112void init(int length) {    /* add your code */}void add(int length, int i) {    /* add your code */}void sum(int lengtha, int lengthb, int lengthc) {    /* add your code */}void diff(int lengtha, int lengthb, int lengthc) {    /* add your code */}


### main.c

123456789101112131415161718192021222324252627282930313233343536#include <stdio.h>#include <assert.h>#include "length.h" int main() {    int a = {-1, -1, -1}, b = {-1, -1, -1};    int c = {-1, -1, -1}, d = {-1, -1, -1};    int e = {-1, -1, -1}, f = {-1, -1, -1};    int cmd, x, y, z;    scanf("%d", &cmd);    if (cmd == 1) {        init(a);        printf("%d %d %d\n", a, a, a);    } else if (cmd == 2) {        init(a);        scanf("%d", &x);        add(a, x);        printf("%d %d %d\n", a, a, a);    } else if (cmd == 3) {        init(a), init(b);        scanf("%d %d", &x, &y);        add(a, x), add(b, y);        sum(a, b, c);        printf("%d %d %d\n", c, c, c);    } else if (cmd == 4) {        init(a), init(b), init(c), init(d);        scanf("%d %d %d", &x, &y, &z);        assert(x+y >= z);        add(a, x), add(b, y);        sum(a, b, c);        add(d, z);        diff(c, d, e);        printf("%d %d %d\n", e, e, e);    }    return 0;}


## Sample Input 1

1


## Sample Output 1

0 0 0


## Sample Input 2

212


## Sample Output 2

0 1 0