Click here to Skip to main content
16,015,756 members

Comments by cadsolution (Top 34 by date)

cadsolution 14-Jan-16 5:10am View    
But i couldn't solve this problem from my self thats why i can share with you.so should solve and suggest the correct one.
cadsolution 14-Jan-16 4:27am View    
in this my code iam using timing is one to nine then its ok.if i want to use moretha nine then stack.pop() stack empty error shown .please see images.also note red color comments in figure1.and figure2 is after debugging error shown like
cadsolution 14-Jan-16 4:11am View    
Deleted
.
cadsolution 14-Jan-16 4:09am View    
here is my error please download below links for better idea.
http://www.mediafire.com/view/4gneoo4uuzb25gb/FIGURE_1%282%29.jpg http://www.mediafire.com/view/regk1u36oyrik37/FIGURE_2%282%29.jpg

here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace txtbox_Content_Sum
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

int combinedSum = 0;

for (char letter = 'A'; letter <= 'D'; letter++)
{
int sum = 0;
var stack = new Stack<string>();
int stackSum = 0;

foreach (string line in textBox1.Lines)
{
string temp = line.Replace(".", "").Replace(" ", ""); // remove dots and spaces
if (temp == "") continue; // ignore blank line
bool containsLetter = (line.IndexOf(letter) > -1);
char first = temp[0];
char last = temp[temp.Length - 1];

if (Char.IsDigit(first))
{
string numStr = temp.Split('-')[0];
if (!containsLetter) numStr = "0";

if (stack.Count == 0)
{
sum += int.Parse(numStr);
}
else
{
stack.Push(numStr);
}

if (Char.IsDigit(last))
{
int multiplier = last - 48;
char bracket = temp[temp.Length - 2];

int total = 0;
char openChar = '\0';
string tempStr;
if (bracket == '}')
openChar = '{';
else if (bracket == ']')
openChar = '[';
else if (bracket == ')')
openChar = '(';
else if (bracket == '>')
openChar = '<';

do
{
tempStr = stack.Pop();
int num;
if (int.TryParse(tempStr, out num)) total += num;
}
while (tempStr[0] != openChar);

stackSum = (stackSum + total) * multiplier;

if (stack.Count == 0)
{
sum += stackSum;
stackSum = 0;
}
}
}
else
{
stack.Push(first.ToString());
int index = 1;

while (true)
{
if (Char.IsDigit(temp[index])) break;
stack.Push(temp[index].ToString());
index++;
}

string numStr2 = temp.Substring(index).Split('-')[0];
if (!containsLetter) numStr2 = "0";
stack.Push(numStr2);

if (Char.IsDigit(last))
{
int multiplier = last - 48;
char bracket = temp[temp.Length - 2];
int total = 0;
char openChar = '\0';
cadsolution 13-Jan-16 7:39am View    
stack empty error shown when iam using morethan 1-9.
tempStr = stack.Pop();

please solve this problem.i could not solve this my side.