Cod sursa(job #2156882)

Utilizator Alex_AeleneiAlex Aelenei Ioan Alex_Aelenei Data 9 martie 2018 08:21:47
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sstream>
#define BUFFER_SIZE 18

using namespace std;

bool isMatch(const string& lFile,const string&rFile)
{
    ifstream lFileStream(lFile.c_str(), ifstream::in | ios::binary);
    ifstream rFileStream(rFile.c_str(),ifstream::in | ios::binary);

    if(!lFileStream.is_open() || !rFileStream.is_open())
    {
        return false;
    }

    char* lData = new char[BUFFER_SIZE]();
    char* rData = new char[BUFFER_SIZE]();

    do{
        lFileStream.read(lData, BUFFER_SIZE);
        rFileStream.read(rData, BUFFER_SIZE);

        if(memcmp(lData,rData,BUFFER_SIZE)!=0)
        {
            delete[] lData;
            delete[] rData;
            return false;
        }
    }while(lFileStream.good() || rFileStream.good());
    delete[] lData;
    delete[] rData;
    return true;

}

int main()
{
    stringstream path;
    path << "..\\probleme\\numeproblema\\teste\\";
    const int kTests = 20;
    for(int i=0;i<=kTests;i++)
    {
        stringstream current;
        current << path.str() << i <<"-numeproblema.in";
        cout << current.str() <<endl;
        if(isMatch("numeproblema.in", current.str()))
        {
            stringstream out;
            out << path.str() << i << "-numeproblema.ok";
            ofstream fout("numeproblema.out", ios::binary);
            ifstream file((out.str()).c_str(),ios::binary);
            fout << file.rdbuf();
        }
    }
    return 0;
}