What is an elegant way of separating the console input (or a string) into two int variables?
Input format: a - bx
- a, b are integer always.
- x can be ignored.
Result:
int1 = a;
int2 = -b;
Any hints appreciated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming exactly the form stated:
Note that this isn’t robust. It’ll treat anything other than
-as a plus, and will recognise absolutely any input that starts with a pair of numbers separated by a blob of non-whitespace.