---
# System prepended metadata

title: Programming Challenges

---

# Programming Challenges

## Divisible By 11

@Azide  - Here's my solution to the problem.
So far this has worked in the compiler, but fails on DMOJ. Any idea why?

``` c
#include <stdio.h>
#include <string.h>

int main() {
    int num[50]; //Int Array
    char input[51]; //Char array (String)
    int N; //Number of expected inputs
    scanf("%d", &N);
    
    for (int i = N; i > 0; i--) { //Loop based on expected inputs (N)
        scanf("%s", &input);
        printf("%s\n", input);
        int len = strlen(input) - 1; //num array will start at index 0
        
        //Transfer characters to int array
        for (int i = 0; input[i] != 0; i++) {
            num[i] = input[i] - 48;
        }
        
        for (int l = len; l > 1; l--) { //Loop until two digits left
            int lastDigit = num[l];
            //Simple subtraction if last digit <= second-to-last
            if (lastDigit <= num[l - 1]) {
                num[l - 1] = num[l - 1] - lastDigit;
            }
            else {
                //Solution if greater, involves regrouping
                num[l - 1] = (num[l - 1] - lastDigit) + 10;
                int j;
                //Check for zeros, if so set to 9
                for (j = l - 2; num[j] == 0; j++) {
                    num[j] = 9;
                }
                num[j] = num[j] - 1;
            }
            
            //Prints the whole array
            if (l != 2) {
                for (int p = 0; p <= l - 1; p++) {
                printf("%d", num[p]);
                }
                //Add new line
                printf("\n");
            }
        }
        
        //When two digits remain, check if divisible by 11
        int finalValue = num[0] * 10 + num[1];
        printf("%d\n", finalValue);
        if (finalValue % 11 == 0) {
            printf("The number ");
            for (int q = 0; q <= len; q++) {
            printf("%c", input[q]);
            }
            printf(" is divisible by 11.\n");
        }
        else {
            printf("The number ");
            for (int r = 0; r <=len; r++) {
            printf("%c", input[r]);
            }
            printf(" is not divisible by 11.\n");
        }
    }
    return 0;
}
```

Looking at tackling this problem next:

## Multiple Choice

[Problem Statment](https://dmoj.ca/problem/ccc11s2/pdf)
@Azide's code

```c
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);
    char student[N];
    char answer[N];
    char value[1];
    int correct = 0;
    
    for (int i = 1; i <= N; i++) {
        scanf("%s", &value);
        strcat(student, value);
    }
    
    for (int j = 1; j <= N; j++) {
        scanf("%s", &value);
        strcat(answer, value);
    }
    
    for (int k = 1; k <= N; k++) {
        if (student[k] == answer[k]) {
            correct++;
        }
    }
    
    printf("%d", correct);
    return 0;
}
```

## Card Game

[Problem Statment](https://dmoj.ca/problem/ccc99s1/pdf)
@Azide's code

```c
#include <stdio.h>

int main() {
    char cards[52][6];
    for (int i = 1; i <= 5; i++) {
        scanf("%s", &cards[i]);
    }
    return 0;
}
```
