UVA - 327 Evaluating Simple C Expressions

The task in this problem is to evaluate a sequence of simple C expressions, buy you need not know C to solve the problem! Each of the expressions will appear on a line by itself and will contain no more than 110 characters. The expressions to be evaluated will contain only simple integer variables and a limited set of operators; there will be no constants in the expressions. There are 26 variables which may appear in our simple expressions, namely those with the names a through z (lower-case letters only). At the beginning of evaluation of each expression, these 26 variables will have the integer values 1 through 26, respectively (that is, a = 1, b = 2, ..., n = 14, o = 15, ..., z = 26). Each variable will appear at most once in an expression, and many variables may not be used at all.

The operators that may appear in expressions include the binary (two-operand) + and -, with the usual interpretation. Thus the expression a + c - d + b has the value 2 (computed as 1 + 3 - 4 + 2). The only other operators that may appear in expressions are ++ and --. These are unary (one-operand) operators, and may appear before or after any variable. When the ++ operator appears before a variable, that variable's value is incremented (by one) before the variable's value is used in determining the value of the entire expression. Thus the value of the expression ++c - b is 2, with c being incremented to 4 prior to evaluating the entire expression. When the ++ operator appears after a variable, that variable is incremented (again, by one) after its value is used to determine the value of the entire expression. Thus the value of the expression c++ - b is 1, but c is incremented after the complete expression is evaluated; its value will still be 4. The -- operator can also be used before or after a variable to decrement (by one) the variable; its placement before or after the variable has the same significance as for the ++ operator. Thus the expression --c + b-- has the value 4, with variables c and b having the values 2 and 1 following the evaluation of the expression.

Here's another, more algorithmic, approach to explaining the ++ and -- operators. We'll consider only the ++ operator, for brevity:

  1. Identify each variable that has a ++ operator before it. Write a simple assignment statement that increments the value of each such variable, and remove the ++ operator from before that variable in the expression.
  2. In a similar manner, identify each variable that has a ++ operator after it. Write a simple assignment statement that increments the value of each of these, and remove the ++ operator from after that variable in the expression.
  3. Now the expression has no ++ operators before or after any variables. Write the statement that evaluates the remaining expression after those statements written in step 1, and before those written in step 2.
  4. Execute the statements generated in step 1, then those generated in step 3, and finally the one generated in step 2, in that order.

Using this approach, evaluating the expression ++a + b++ is equivalent to computing

  • a = a + 1 (from step 1 of the algorithm)
  • expression = a + b (from step 3)
  • b = b + 1 (from step 2)

where expression would receive the value of the complete expression.

Input and Output

Your program is to read expressions, one per line, until the end of the file is reached. Display each expression exactly as it was read, then display the value of the entire expression, and on separate lines, the value of each variable after the expression was evaluated. Do not display the value of variables that were not used in the expression. The samples shown below illustrate the desired exact output format.

Blanks are to be ignored in evaluating expressions, and you are assured that ambiguous expressions like a+++b (ambiguous because it could be treated as a++ + b or a + ++b) will not appear in the input. Likewise, ++ or -- operators will never appear both before and after a single variable. Thus expressions like ++a++ will not be in the input data.

Sample Input

a + b
b - z
a+b--+c++
c+f--+--a
   f-- + c-- + d-++e

Sample Output

Expression: a + b
    value = 3
    a = 1
    b = 2
Expression: b - z
    value = -24
    b = 2
    z = 26
Expression: a+b--+c++
    value = 6
    a = 1
    b = 1
    c = 4
Expression: c+f--+--a
    value = 9
    a = 0
    c = 3
    f = 5
Expression:    f-- + c-- + d-++e
    value = 7
    c = 2
    d = 4
    e = 6
    f = 5


#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>

using namespace std;

char str[200];
string res;

int main()
{
	while( getline( cin , res ) )
	{
		cout << "Expression: " << res << endl;

		memset( str , 0 , sizeof(str));

		int index = 0 ;
		for(int i = 0 ;i < res.size() ; i ++)
		{
			if( res[i] >= 'a' && res[i] <= 'z' || res[i] == '+' || res[i] == '-')
				str[index++] = res[i];
		}

		int num1[26] ,num2[26], f[26];
		for(int i = 0 ; i < 26 ;i ++) num1[i] = i+1,num2[i] = i + 1, f[i] = 0;

		int len = index,value = 0, a1 = 0 , a2 =0;

		for(int i = 0 ;i < len; i ++)
		{
			if( str[i] >= 'a' && str[i] <= 'z' )
			{
				f[str[i] - 'a'] = 1;
			}
			if( str[i] == '+' && str[i+1] == '+' && str[i+2] >='a' && str[i+2] <= 'z' )
			{
				f[str[i+2] - 'a'] = 1;
				num1[str[i+2] - 'a'] ++;
				num2[str[i+2] - 'a'] ++;
				str[i] = 'A';
				str[i+1] = 'A';

			}
			if( str[i] == '-' && str[i+1] == '-' && str[i+2] >='a' && str[i+2] <= 'z' )
			{
				f[str[i+2] - 'a'] = 1;
				num1[str[i+2] - 'a'] --;
				num2[str[i+2] - 'a'] --;
				str[i] = 'A';
				str[i+1] = 'A';
			}
			if(  str[i] >='a' && str[i] <= 'z' && str[i+1] == '+' && str[i+2] == '+' )
			{
				f[str[i] - 'a'] = 1;
				num1[str[i] - 'a'] ++;
				str[i+1] = 'A';
				str[i+2] = 'A';
			}
			if( str[i] >='a' && str[i] <= 'z' && str[i+1] == '-' && str[i+2] == '-' )
			{
				f[str[i] - 'a'] = 1;
				num1[str[i] - 'a'] --;
				str[i+1] = 'A';
				str[i+2] = 'A';
			}
		}

		bool flag = true;
		for(int i = 0;i < len ;i ++)
		{
			if( str[i] >= 'a' && str[i] <= 'z' && flag )
			{
				flag = false;
				value += num2[str[i] - 'a'];
			}
			else if( str[i] == '+' || str[i] == '-' )
			{
				if( str[i] == '+' )
				{
					for(int j = i;  ;j ++ )
					{
						if( str[j] >= 'a' && str[j] <= 'z' )
						{
							value += num2[str[j] - 'a'];
							break;
						}
					}
				}
				else if( str[i] == '-' )
				{
					for(int j = i;  ;j ++)
					{
						if( str[j] >= 'a' && str[j] <= 'z' )
						{
							value -= num2[str[j] - 'a'];
							break;
						}
					}
				}
			}
		}

		cout << "    value = " << value << endl;

		for(int i = 0 ;i < 26 ;i ++)
		{
			if( f[i] )
			{
				cout <<"    " << (char)(i + 'a') << " = " << num1[i] << endl;
			}
		}
	}
	return 0;
}


"大规模基准数据集用于评估泛锐化性能"是一个用于评估图像泛锐化算法表现的数据集。泛锐化是一种图像处理技术,旨在通过将低分辨率的多光谱图像与高分辨率的全色图像融合,以产生具有较高空间分辨率和丰富光谱信息的图像。这种技术在许多遥感应用中都很有用,例如土地利用监测、资源管理和环境监测。 该数据集的规模大,包含了大量的多光谱和全色图像对,这些图像对均具有全面的注释和质量测量指标。这些图像对来自各种不同的遥感源,涵盖不同的场景和条件。数据集的构建过程经过精心设计,以保证评估结果的准确性和可靠性。 使用该数据集,研究人员和开发者可以对他们的泛锐化算法进行全面的评估和对比。他们可以将自己的算法应用于数据集中的图像对,并使用数据集中提供的注释进行性能评估。这些注释可以包括图像质量评价指标,如结构相似性指数(SSIM)和峰值信噪比(PSNR),或者一些更复杂的图像质量评价方法,如目标检测和目标分类任务的准确率。通过与其他算法进行比较,开发者可以了解他们的算法在不同场景和条件下的表现如何,并进一步改进和优化他们的方法。 "大规模基准数据集用于评估泛锐化性能"的建立为泛锐化算法的发展提供了一个公共的平台,促进了该领域的研究和进步。研究人员和开发者可以根据数据集中的结果和经验得出更好的算法和技术,进一步提高泛锐化算法在实际应用中的效果。这个数据集的存在为遥感图像处理的研究和应用带来了很大的推动力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值