If you haven't done questions for a long time, you have to do water questions ....
Using map in C ++ to map numbers and strings is nothing else.
[Cpp] # include <map>
# Include <iostream>
# Include <string>
Using namespace std;
Map <string, int> m;
Int main ()
{
M ["one"] = 1;
M ["two"] = 2;
M ["three"] = 3;
M ["four"] = 4;
M ["five"] = 5;
M ["six"] = 6;
M ["seven"] = 7;
M ["eight"] = 8;
M ["nine"] = 9;
M ["zero"] = 0;
Char s [15];
Int a, B;
While (cin> s)
{
A = B = 0;
While (strcmp (s, "+ "))
{
A = a * 10 + m [s];
Cin> s;
}
Cin> s;
While (strcmp (s, "= "))
{
B = B * 10 + m [s];
Cin> s;
}
If (a = 0 & B = 0) break;
Cout <a + B <endl;
}
Return 0;
}
# Include <map>
# Include <iostream>
# Include <string>
Using namespace std;
Map <string, int> m;
Int main ()
{
M ["one"] = 1;
M ["two"] = 2;
M ["three"] = 3;
M ["four"] = 4;
M ["five"] = 5;
M ["six"] = 6;
M ["seven"] = 7;
M ["eight"] = 8;
M ["nine"] = 9;
M ["zero"] = 0;
Char s [15];
Int a, B;
While (cin> s)
{
A = B = 0;
While (strcmp (s, "+ "))
{
A = a * 10 + m [s];
Cin> s;
}
Cin> s;
While (strcmp (s, "= "))
{
B = B * 10 + m [s];
Cin> s;
}
If (a = 0 & B = 0) break;
Cout <a + B <endl;
}
Return 0;
}