NicolaDelPrete

Lettura e scrittura

Oct 7th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. class Esercizio{
  7.  
  8.     string app1,app2;
  9. public:
  10.     Esercizio (){}
  11.     void soluzione();
  12. };
  13. void Esercizio::soluzione(){
  14.     ifstream probl("Problema.txt");
  15.     ifstream sol("Soluzione.txt");
  16.     ofstream es("Esito.txt");
  17.     while(!sol.eof())
  18.     {
  19.         getline(probl, app1);
  20.         getline(sol, app2);
  21.         int j=1,verifica=1;
  22.         for(int i=0; i< app1.size(); i++)
  23.         {
  24.             if(app1.at(i)==app2.at(j))
  25.             {
  26.                 if(app1.at(i)=='>')
  27.                 {
  28.                     if(app2.at(j-1)<app2.at(j+1))
  29.                     {
  30.                         i=70;
  31.                         verifica=0;
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                    if(app2.at(j-1)>app2.at(j+1))
  37.                     {
  38.                         i=70;
  39.                         verifica=0;
  40.                     }
  41.                 }
  42.             }
  43.             else
  44.             {
  45.                 i=70;verifica=0;
  46.             }
  47.             j+=2;
  48.         }
  49.         if(verifica==0)
  50.         {
  51.             es<<"Sbagliato!"<<endl;
  52.         }
  53.         else
  54.         {
  55.            es<<"Esatto!"<<endl;
  56.         }
  57.     }
  58. }
  59.  
  60. int main()
  61. {
  62.     Esercizio q;
  63.     q.soluzione();
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment