Enter
Each row an arithmetic type, shape such as a + b=c, a - b=c, a + b=, a - b=, 0 or less a, b, c or less 100
O
Output the correct title number,
The sample input
1 + 1=2
1 + 2=4
2-1=1
2-2=
3 + 6=
Sample output
2
This is the online code:
# include
using namespace std;
Char s [50];
Int main () {
Int d1, d2, d3,
int cnt=0;
Char op;
While (gets (s)) {
D3=1000;
Sscanf (s, "% d %=c % d % d", & amp; D1, & amp; Op, & amp; D2, & amp; D3);
If (d1 + d2==d3 & amp; & Op=='+')
{
cnt++;
}
If (d1, d2==d3 & amp; & Op=='-')
{
cnt++;
}
}
Printf (" % d \ n ", CNT);
return 0;
}
Don't understand here gets and sscanf function, can't use the scanf?
And the input output only enter CTRL + Z CNT is mentally
And when the d3 is a space, sscanf (s, "% d % d % c=% d", & amp; D1, & amp; Op, & amp; D2, & amp; D3); Is how to deal with
CodePudding user response:
Well, can use the,//# include
# include & lt; Stdio. H>
# include & lt; Stdlib. H>
//using namespace STD.
Char s [50];
Int main () {
Int d1, d2, d3,
int cnt=0;
Char op;
//while (gets (s)) {
While (the scanf (" % d %=c % d % d ", & amp; D1, & amp; Op, & amp; D2, & amp; D3)={
=4)//d3=1000;
//sscanf (s, "% d %=c % d % d", & amp; D1, & amp; Op, & amp; D2, & amp; D3);
If (d1 + d2==d3 & amp; & Op=='+')
{
cnt++;
}
If (d1, d2==d3 & amp; & Op=='-')
{
cnt++;
}
}
Printf (" % d \ n ", CNT);
return 0;
}
For your reference ~
Suggest check sscanf function; Can be thought of as the scanf matches the value read from s % % d and c
CodePudding user response:
The