View Code of Problem 16

#include<iostream>
#include<string>

using namespace std;

int main()
{
	int t;
	char s[20];
	cin >> t;
	while(t--)
	{
		int sign;
		int x = 0, y = 0;
		cin >> sign;
		scanf("%s", s);
		while(s[0] != '+')
		{
			if(s[0] >= '0' && s[0] <= '9')
				for(int i = 0; s[i] != '\0'; i++)
				{
					x *= 10;
					x += s[i] - 48;
				}
			else
			{
				switch(s[0])
				{
					case 'o':x *= 10;
							x++;
							break;
							
					case 't':x *= 10;
							if(s[1] == 'w')
								x += 2;
							else
								x += 3;
							 break;
						
					case 'f':x *= 10;
							if(s[1] == 'o')
								x += 4;
							else
								x += 5;
							 break;
						
					case 's':x *= 10;
							if(s[1] == 'i')
								x += 6;
							else
								x += 7;
							 break;
						
					case 'e':x *= 10;
							x += 8;
							break;
						
					case 'n':x *= 10;
							x += 9;
							break;
					
					case 'z':x *= 10;
							break;
				}
			}	
			scanf("%s", s);
		}
		
		scanf("%s", s);
		while(s[0] != '=')
		{
			if(s[0] >= '0' && s[0] <= '9')
				for(int i = 0; s[i] != '\0'; i++)
				{
					y *= 10;
					y += s[i] - 48;
				}
			else
			{
				switch(s[0])
				{
					case 'o':y *= 10;
							y++;
							break;
							
					case 't':y *= 10;
							if(s[1] == 'w')
								y += 2;
							else
								y += 3;
							 break;
						
					case 'f':y *= 10;
							if(s[1] == 'o')
								y += 4;
							else
								y += 5;
							 break;
						
					case 's':y *= 10;
							if(s[1] == 'i')
								y += 6;
							else
								y += 7;
							 break;
						
					case 'e':y *= 10;
							y += 8;
							break;
						
					case 'n':y *= 10;
							y += 9;
							break;
					
					case 'z':y *= 10;
							break;
				}
			}	
			scanf("%s", s);
		}
		
		int z = x + y;
		if(sign)
		{
			string str = to_string(z);
			for(int i = 0; str[i] != '\0'; i++)
			{
				if(i != 0)
					cout << " ";
				switch(str[i])
				{
					case '0':cout << "zero";
							break;
					case '1':cout << "one";
							break;
					case '2':cout << "two";
							break;
					case '3':cout << "three";
							break;
					case '4':cout << "four";
							break;		
					case '5':cout << "five";
							break;
					case '6':cout << "six";
							break;
					case '7':cout << "seven";
							break;		
					case '8':cout << "eight";
							break;
					case '9':cout << "nine";
							break;
				}
			}
			cout << endl;	
		}
		else
			cout << z << endl;
		
	}
	return 0; 
}

Double click to view unformatted code.


Back to problem 16