All pastes #597273 Raw Edit

Miscellany

public text v1 · immutable
#597273 ·published 2007-06-30 14:29 UTC
rendered paste body
#include <iostream>
using namespace std;

int main(void) {
        int x=0;
        int z=0;
        string mj;
        string p1;
        string p2;

        getline(cin, mj);

        if (mj.find(" ") == string::npos) {
                cout << "Lauseke on virheellinen|" << mj << "\n";
        }
        else {
                p1 = mj.substr(0,mj.find(" "));
                if (p1.compare(p1.length()-1,1,"x")==0) {
                        x = atoi(p1.substr(0,p1.length()-1).c_str());
                }
                else {
                        z = atoi(p1.substr(0,p1.length()-1).c_str());
                }
                p2 = mj.substr(mj.find(" ")+1,mj.length());
                if (p2.compare(p2.length()-1,1,"x")==0) {
                        x = atoi(p2.substr(0,p2.length()-1).c_str());
                }
                else {
                        z = atoi(p2.substr(0,p2.length()-1).c_str());
                }
        }
        cout << x*4 + z*5 << "\n";
}