xxxxxxxxxx
#include <iostream>
using namespace std;
int main () {
String a;
cin>>a; //takes b and stores it into a variable
cout<<a; //should output b
}
xxxxxxxxxx
// To take input from a string instead of stdin, you can you use std::istringstream
// This is useful in a lot of UVA problems
// This is an Example for it using a simple calculator
#include <iostream>
// sstream should be included to use istringstream
#include <sstream>
using namespace std;
// This function takes a line input and return the equation as a tuple
tuple<int, char, int> getEquationFromLine(string line){
// Let's say Line is "2 + 3"
int firstNumber, secondNumber;
char operation;
istringstream iss(line);
iss >> firstNumber;
// firstNumber is now 2
iss >> operation;
// operation is now +
iss >> secondNumber;
// secondNumber is now 3
return {firstNumber, operation, secondNumber};
}
int main() {
string equationLine;
getline(cin, equationLine);
tuple<int, char, int> equation = getEquationFromLine(equationLine);
// Just printing the answer of the equation
switch (get<1>(equation)) {
case '+': cout << get<0>(equation) + get<2>(equation);
break;
case '-': cout << get<0>(equation) - get<2>(equation);
break;
case '*': cout << get<0>(equation) * get<2>(equation);
break;
case '/': cout << get<0>(equation) / (double)get<2>(equation);
break;
default:cout << "INVALID";
}
}