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

Re:用getchar()读取各种TLE 改成cin>>string之后直接16MS过

Posted by 15914304086 at 2012-03-13 19:16:01 on Problem 2295 and last updated at 2012-03-13 19:19:22
In Reply To:用getchar()读取各种TLE 改成cin>>string之后直接16MS过 Posted by:xuchang at 2011-01-20 15:48:28
从输入流cin中读入处理数据很容易超时,建议用string整条读入后处理,本人0s读入
void get(int &x,int &c)//x是整条式子X的系数和,c是常数和。
{
	string g;
	cin>>g;
	int i=0,l=g.length(),fuhao,denghao=1,shu;	
	while (i<l)
	{
		if (g[i]=='=')
			{
				denghao=-1;
				i++;
			}
		else
		{
			shu=1;
			if (g[i]=='-')
			{
				fuhao=0-denghao;
				i++;
			}
			else//
			{
				fuhao=denghao;
				if (g[i]=='+')
				{
					i++;
				}
			}
			if (g[i]>='0' && g[i]<='9')
			{
				shu=0;
				while(g[i]>='0' && g[i]<='9')
				{
					shu=shu*10+g[i]-48;
					i++;
				}
			}
			shu*=fuhao;
			if (g[i]=='x')
			{
				x+=shu;
				i++;
			}
			else
			{
				c+=shu;
			}
		}
	}
}

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