Cod sursa(job #1851921)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 20 ianuarie 2017 12:05:54
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

vector <int> sol{0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 7, 8, 4, 7, 3, 8, 4, 1, 5, 4, 4, 5, 9, 6, 2, 7, 3, 6, 2, 1, 1, 2, 8, 1, 7, 2, 8, 5, 9, 8, 8, 9, 3, 0, 6, 1, 7, 0, 6, 5, 5, 6, 2, 5, 1, 6, 2, 9, 3, 2, 2, 3, 7, 4, 0, 5, 1, 4, 0, 9, 9, 0, 6, 9, 5, 0, 6, 3, 7, 6, 6, 7, 1, 8, 4, 9, 5, 8, 4, 3, 3, 4, 0, 3, 9, 4, 0, 7, 1, 0, 0};

class parser{
    public:
        parser() {}
        parser(const char *file_name){
            input_file.open(file_name);
            input_file.sync_with_stdio(false);
            input_file.getline(trash,110);
            cursor=0;
            input_file.read(buffer,SIZE);}
        inline parser &operator >>(int &n){
            int last,current;
            while(buffer[cursor]<'0' or buffer[cursor]>'9') inc();
            n=last=current=0;
            while('0'<=buffer[cursor] and buffer[cursor]<='9'){
                last=current;
                current=buffer[cursor]-'0';
                inc();
            }
            n=sol[last*10+current];
            return *this;}
    private:
        ifstream input_file;
        static const int SIZE=0x8000;
        char buffer[SIZE],trash[110];
        int cursor=0;
        inline void inc(){
            if(++cursor==SIZE)
                cursor=0,input_file.read(buffer,SIZE);
        }
};

parser f ("cifra.in");
ofstream t ("cifra.out");

int main()
{
    freopen("cifra.in", "r", stdin);
    int n;
    scanf("%d ", &n);
    for (int aux,i=0;i<n;++i){
        f>>aux;
        t<<aux<<endl;
    }
    return 0;
}