ABSYS – Anti-Blot System


Jimmy is a hard-working pupil in his second year at primary school. Recently he decided to convert all his notes into an electronic version. Sadly, he found that his math notes were full of ink blots.

He scanned the notes and sent them through his own OCR package (yes, he coded it all by himself at the age of 8). The OCR package replaced all ink blots by the string “machula“.

Read More Here

Hint: Operands and result is positive only. Beware of output format.


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;

bool notaNumber(string str, lli &number){
    string::iterator it1 = str.begin();
    while(it1!=str.end() && isdigit(*it1)) {
     number = number*10 + (*it1-'0');
    return !(it1==str.end());

int main() {
	lli T;
	string op1,opa1,opa2, op2, result;
	    bool t1,t2,t3;
	    lli num1=0,num2=0,num3=0;
	    t1 = notaNumber(op1,num1);
	    t2 = notaNumber(op2,num2);
	    t3 = notaNumber(result,num3);
	        cout<<(num3-num2)<<" + "<<num2<<" = "<<num3<<endl;
	    else if(t2)
	        cout<<num1<<" + "<<(num3-num1)<<" = "<<num3<<endl;
	        cout<<num1<<" + "<<num2<<" = "<<(num1+num2)<<endl;
	return 0;

Explanation: Take both operand and result in string and check if that are numbers or not. In above code notaNumber function is doing that work and also calculating the number if the given string is number.

Not good with STL library? Try this book C++: The Complete Reference, 4th Edition

Share This:

Next Post

Previous Post

© 2017 Kodemonk

Theme by Anders Norén