Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁能帮我看看程序啊。。总是错哦。。。

Posted by xax10000 at 2005-07-17 23:29:25 on Problem 1539
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int a[26];
int result[100];
int main(int argc, char* argv[])
{
	char s[100];
	int i;
	while(cin.getline(s,100))
	{
		string str = s;
		for(i=0;i<26;++i)a[i] = i + 1;
		fill(result,result + 100, 0);
		int flag[26] = {0};
		long sum = 0;
		for(i=0;i<strlen(s);i++)
		{
			if(s[i]>='a' &&  s[i]<='z')
			{
				flag[s[i]-'a'] = 1;
				if(i>=2)
				{
					if(s[i-1]==s[i-2])
					{
						if(s[i-1] == '-')
						{
							a[s[i]-'a'] --;
							s[i-1] = s[i-2] = ' ';
							result[i] = a[s[i]-'a'];
							continue;
						}
						if(s[i-1] == '+')
						{
							a[s[i]-'a'] ++;
							s[i-1] = s[i-2] = ' ';
							result[i] = a[s[i]-'a'];
							continue;
						}
					}
				}
				if(i+2<strlen(s))
				{
					if(s[i+1]==s[i+2])
					{
						if(s[i+1]=='-')
						{
							result[i] = a[s[i]-'a'];
							a[s[i]-'a'] --;
							s[i+1] = s[i+2] = ' '; 
							continue;
						}
						if(s[i+1]=='+')
						{
							result[i] = a[s[i]-'a'];
							a[s[i]-'a'] ++;
							s[i+1] = s[i+2] = ' ';
							continue;
						}
					}
				}
				result[i] = a[s[i]-'a'];
			}
		}
		char ch = ' ';
		sum = 0;
		for(i=0;i<strlen(s);++i)
		{
			if(s[i]==' ')continue;
			if(s[i]=='-'){ch='-';continue;}
			if(s[i]=='+'){ch='+';continue;}
			if(ch==' ' || ch=='+')sum += result[i];
			if(ch=='-')sum -= result[i];
		}
		cout<<"Expression: "<<str<<endl;
		cout<<"    value = "<<sum<<endl;
		for(i=0;i<26;++i)
		{
			if(flag[i])
				cout<<"    "<<char('a'+i)<<" = "<<a[i]<<endl;
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator