<commit_before>#include <iostream>
#include <cstring>
#include "Stack.h"
#include "StringTokenizer.h"
#include "StringUtils.h"

int getPriority(char op)
{
    if (op == '+' || op == '-' || op == '(')
    {
        return 0;
    } else if (op == '/' || op == '*')
    {
        return 1;
    }
}
string translateToPostfix(string);
int calculate(string);
int main(int argc,char** args)
{
	using namespace std;
	cout << "Input:" << endl;
	char* in = new char[256];
	cin.getline(in,256);
	string postfix(translateToPostfix(in));
	cout << "Postfix:" << postfix << endl;
	cout << "Output: " << calculate(postfix) << endl;
	
}

string translateToPostfix(string input)
{
	Stack<char> stack;
	string output;
	StringTokenizer tokenizer(input);
	while (tokenizer.hasNext())
	{
		char* token = tokenizer.next();
		cout << "parse " << token << endl;
		if (StringUtils::contain(token,'('))
		{
			stack.put('(');
		}
		else if (StringUtils::contain(token,')'))
		{
			char out;
			while((out = stack.pop()) != '(')
				{
				output += out;
				output += " ";
            }
		}
		else if (StringUtils::contain(token,'+'))
		{
			char top = stack.peek();
				while(getPriority(top) > 0 && stack.getCapability() != -1)
				{
					output += stack.pop();
					output += " ";
					top = stack.peek();
				}
				stack.put('+');
		}
		else if (StringUtils::contain(token,'-'))
		{
			char top = stack.peek();
				while(getPriority(top) > 0 && stack.getCapability() != -1)
				{
					output += stack.pop();
					output += " ";
					top = stack.peek();
				}
				stack.put('-');
		}
		else if (StringUtils::contain(token,'*'))
		{
			stack.put('*');
		}
		else if (StringUtils::contain(token,'/'))
		{
			stack.put('/');
		}
		else
		{
			output += token;
			output += " ";
		}
	}
	while(stack.getCapability() != -1)
	{
		output += stack.pop();
	}
	cout << "return :" << output << endl;
	return output;
}

int calculate(string postfix)
{
	StringTokenizer tokenizer(postfix);
	Stack<int> stack;
	while (tokenizer.hasNext())
	{
		char* token = tokenizer.next();
		if (StringUtils::contain(token, '+'))
		{
			stack.put(stack.pop() + stack.pop());
		}
		else if (StringUtils::contain(token, '-'))
		{
			stack.put(stack.pop() - stack.pop());
		}
		else if (StringUtils::contain(token, '*'))
		{
			stack.put(stack.pop() * stack.pop());
		}
		else if (StringUtils::contain(token, '/'))
		{
			int rv = stack.pop();
			int lv = stack.pop();
			stack.put(lv/rv);
		}
		else
		{
			stack.put(StringUtils::strToInt(token));
		}
	}
	return stack.pop();
}<commit_msg>change the return type of calculate function into double<commit_after>#include <iostream>
#include <string>
#include "Stack.h"
#include "StringTokenizer.h"
#include "StringUtils.h"
using namespace std;
int getPriority(char op)
{
    if (op == '+' || op == '-' || op == '(')
    {
        return 0;
    } else if (op == '/' || op == '*')
    {
        return 1;
    }
}
string translateToPostfix(string);
double calculate(string);
int main(int argc,char** args)
{
	using namespace std;
	cout << "Input:" << endl;
	char* in = new char[256];
	cin.getline(in,256);
	string postfix(translateToPostfix(in));
	cout << "Postfix:" << postfix << endl;
	cout << "Output: " << (double)calculate(postfix) << endl;
	return 0;
}

string translateToPostfix(string input)
{
	Stack<char> stack;
	string output;
	StringTokenizer tokenizer(input);
	while (tokenizer.hasNext())
	{
		char* token = tokenizer.next();
		if (StringUtils::contain(token,'('))
		{
			stack.put('(');
		}
		else if (StringUtils::contain(token,')'))
		{
			char out;
			while((out = stack.pop()) != '(')
				{
				output += out;
				output += " ";
            }
		}
		else if (StringUtils::contain(token,'+'))
		{
			char top = stack.peek();
				while(getPriority(top) > 0 && stack.getCapability() != -1)
				{
					output += stack.pop();
					output += " ";
					top = stack.peek();
				}
				stack.put('+');
		}
		else if (StringUtils::contain(token,'-'))
		{
			char top = stack.peek();
				while(getPriority(top) > 0 && stack.getCapability() != -1)
				{
					output += stack.pop();
					output += " ";
					top = stack.peek();
				}
				stack.put('-');
		}
		else if (StringUtils::contain(token,'*'))
		{
			stack.put('*');
		}
		else if (StringUtils::contain(token,'/'))
		{
			stack.put('/');
		}
		else
		{
			output += token;
			output += " ";
		}
	}
	while(stack.getCapability() != -1)
	{
		output += stack.pop();
		output += " ";
	}
	return output.substr(0,output.size() - 1);
}

double calculate(string postfix)
{
	StringTokenizer tokenizer(postfix);
	Stack<double> stack;
	while (tokenizer.hasNext())
	{
		char* token = tokenizer.next();
		if (StringUtils::contain(token, '+'))
		{
			stack.put(stack.pop() + stack.pop());
		}
		else if (StringUtils::contain(token, '-'))
		{
			double rv = stack.pop();
			double lv = stack.pop();
			stack.put(lv - rv);
		}
		else if (StringUtils::contain(token, '*'))
		{
			stack.put(stack.pop() * stack.pop());
		}
		else if (StringUtils::contain(token, '/'))
		{
			double rv = stack.pop();
			double lv = stack.pop();
			stack.put(lv/rv);
		}
		else
		{
			stack.put(StringUtils::strToDouble(token));
		}
	}
	double result = stack.pop();
	return result;
}
{'fraction_non_alphanumeric': 0.2051973051010587, 'fraction_numerical': 0.005582290664100096, 'mean_word_length': 3.0562060889929743, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3168468', 'n_tokens_mistral': 2202, 'n_tokens_neox': 1913, 'n_words': 374}