Advertisement
VladSmirN

five8

Nov 23rd, 2020
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include "pt4.h"
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. void Solve()
  6. {
  7.     Task("Five8");
  8.     string FN1,FN2,s;
  9.     pt>>FN1>>FN2;
  10.     ifstream filei (FN1);
  11.     ofstream fileo (FN2);
  12.     while(filei>>s)
  13.     {
  14.         string s1,s2,s3;
  15.         if(s.find("+") != -1)
  16.         {
  17.             s1 = s.substr(0, s.find("+"));
  18.             s2 = s.substr(s.find("+")+1, s.find("=")-s1.size()-1);
  19.             s3 = s.substr(s.find("=")+1, s.size()-s2.size());
  20.  
  21.             if(strtol(s1.c_str() , 0, 2 )+ strtol(s2.c_str() , 0, 2 ) != strtol(s3.c_str() , 0, 2 )){
  22.  
  23.                 fileo<<s+" -"<<endl;
  24.  
  25.             }else{
  26.                 fileo<<s<<endl;
  27.             }
  28.  
  29.  
  30.  
  31.         }
  32.         else
  33.         {
  34.             s1 = s.substr(0, s.find("*"));
  35.             s2 = s.substr(s.find("*")+1, s.find("=")-s1.size()-1);
  36.             s3 = s.substr(s.find("=")+1, s.size()-s2.size());
  37.             if(strtol(s1.c_str() , 0, 2 ) * strtol(s2.c_str() , 0, 2 ) != strtol(s3.c_str() , 0, 2 )){
  38.  
  39.                 fileo<<s+" -"<<endl;
  40.  
  41.             }else{
  42.                 fileo<<s<<endl;
  43.             }
  44.  
  45.         }
  46.  
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement