Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Processing a string- CodeChef Solution in CPP

#include<iostream>
#include<stack>
using namespace std;

int sum(string exp);
bool IsNumber(char ch);

int main()
{
	string exp;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> exp;
		int result = sum(exp);
		cout << result << endl;
	}
	

	return 0;
}
//
int sum(string exp)
{
	stack<char> s;
	int sum = 0;
	for (int i = 0; i < exp.length(); i++)
	{
		if (IsNumber(exp[i]))
		{
			s.push(exp[i] - '0');
			sum += s.top();
		}
		else
		{
			continue;
		}
	}
	return sum;
}
//
bool IsNumber(char ch)
{
	if (ch >= '0' && ch <= '9')
		return true;
	return false;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Lapindromes codechef solution in c++ 
Cpp :: gcd of two number in c++ stl 
Cpp :: dijkstra algorithm in c++ geeksforgeeks 
Cpp :: c++ Is there still a need to provide default constructors to use STL containers 
Cpp :: (/~/+|/+$/g, ') 
Cpp :: remove element from vector c++ by index 
Cpp :: how to make negative number positive in c++ 
Cpp :: amusia 
Cpp :: cuda atomic swap 
Cpp :: how to initialize a vector in c++ 
Cpp :: while loop in c++ 
Cpp :: c++ shift array to the right 
Cpp :: default access specifier in c++ 
Cpp :: declare a variable in cpp 
Cpp :: what do we use c++ vectors for 
Cpp :: imgui menu bar 
Cpp :: c++ delete int 
Cpp :: friend class c++ 
C :: unity change transparency script 
C :: pygame detect click 
C :: Invalid public key for CUDA apt repository 
C :: roshan kumar 
C :: types of instruction and there meaning in c 
C :: npm fix old lockfile 
C :: srand time null 
C :: how to sleep in c 
C :: redirect to url page asp.net mvc 
C :: how make a character in c scanf 
C :: c print to stderr 
C :: read from stdin c 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =