Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
                                                        C++ Programming
#include <cstdio>
int main(){
    FILE * inputFile = fopen("input.txt","r");
    int ball(0); fscanf(inputFile, "%d\n", &ball);
    const int N = 3;
    for(int p = 0; p < N; p++){
        int first(0), second(0); fscanf(inputFile, "%d %d\n", &first, &second);
        if(first == ball){ball = second;}
        else if(second == ball){ball = first;}
    }
    fclose(inputFile);
    FILE * outputFile = fopen("output.txt","w");
    fprintf(outputFile, "%d\n", ball);
    fclose(outputFile);
    return 0;
}Input
                                                            1
1 2
2 1
2 1
                                                    1 2
2 1
2 1
Output
                                                            2
                                                                                                                    
                                                    Demonstration
Codeforces Solution-A. Shell Game-Solution in C, C++, Java, Python
