| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:用getchar()读取各种TLE 改成cin>>string之后直接16MS过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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator