Hi everyone! I have a problem that I can't solve by myself.. My program is compiled but after I write the number of variable n after its start, the program stop working..
Does anyone have any idea how to solve this?
My input should looks like these:
9
+ 4
+ 3
-
+ 3
-
-
-
+ 2
-
And output should looks like these:
OK
OK
3
OK
3
4
BLAD
OK
2
Don't use scanf. it's unsafe and nasty. Even the safe version (scanf_s) I'd steer clear of. Use c++ IO constructs like 'cin'.
Consider using std::string (you are using them in some places so i don't know why you're using chars in other places ).
something like this:
1 2 3 4 5 6 7 8 9 10
....
for (int i = 0; i < n; i++){
std::string s("");//variable to save sign
cin >> s;
if (s.find("+") != string::npos) // <- is there a + in my string
{
....
I know that better idea is to use cin than scanf but this exercise what I do know exercise from Spoj, when i tried to use cin Spoj write me an error message "
Timeout error" and when i use scanf Spoj doesnt show this error..
You aren't using scanf() correctly. This one of the reasons to avoid it. Line 18 should be scanf("%c", &s) and line 23 won't work at all because scanf() doesn't work with strings.
Converting to cin as mutexe suggested. This also reads the numbers directly instead of reading to a string and parsing it. See other comments throughout.