- 表达式求值
- 2014-09-08 10:54:00 @
const m=10000;
var s:array[1..100000]of char;
p,len,t,ans,i:longint;
function getnum:longint;
var sum:longint;
begin
sum:=0;
while (s[p]>='0')and(s[p]<='9') do
begin
sum:=sum*10+ord(s[p])-ord('0');
inc(p);
end;
exit(sum);
end;
begin
while not seekeof do
begin
inc(i);
read(s[i]);
end;
len:=i;
p:=1;
ans:=0;
while p<=len do
begin
t:=getnum mod m;
while (p<=len) and (s[p]='*') do
begin
inc(p);
t:=t*(getnum mod m)mod m;
end;
ans:=(ans+t)mod m;
inc(p);
end;
writeln(ans);
end.
3 条评论
-
1216822876 LV 9 @ 2015-08-01 11:14:41
测试数据 #0: Accepted, time = 0 ms, mem = 884 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 1184 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 1180 KiB, score = 10
测试数据 #3: Accepted, time = 19 ms, mem = 1180 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 1184 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 1180 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 1180 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 1180 KiB, score = 10
测试数据 #8: RuntimeError, time = 15 ms, mem = 2208 KiB, score = 0
测试数据 #9: RuntimeError, time = 16 ms, mem = 2208 KiB, score = 0
RuntimeError, time = 50 ms, mem = 2208 KiB, score = 80
代码
var
n,m,u,d,w,v,x,t:int64;
i,j,l:longint;
a:array[0..10000]of longint;
c:array[0..10000]of char;
f:array[0..1000,0..1000]of longint;
s,ss:ansistring;
begin
readln(s);
n:=0;d:=0;
for i:=1 to length(s) do
begin
if (s[i]='+')or(s[i]='*') then
begin
inc(n);
c[n]:=s[i];
if i-d-1>4 then
begin
ss:=copy(s,i-4,4);
val(ss,a[n]);
end else
begin
ss:=copy(s,d+1,i-d-1);
val(ss,a[n]);
end;
d:=i;
end;
end;
ss:=copy(s,d+1,length(s)-d);
val(ss,a[n+1]);
for i:=1 to n do
if c[i]='*' then
begin
a[i+1]:=a[i]*a[i+1]mod 10000;
a[i]:=0;
end;
t:=0;
for i:=1 to n+1 do t:=(t+a[i])mod 10000;
writeln(t);
readln;
end. -
2014-09-08 14:16:24@
program P1849;
var
y:ansistring;
a:array[1..100001]of int64;
z:array[1..100001]of char;
i,j:dword;o,ans,n:qword;x:char;
begin
o:=1;ans:=0;repeat read(x);if not (x in['+','*'])then y:=y+x;
if x in['+','*']then begin z[o]:=x;val(y,a[o]);y:='';inc(o);end;until eoln;val(y,a[o]);
for i:=1 to o do if (z[i]='*') then begin a[i]:=(a[i]mod 10000*a[i+1]mod 10000)mod 10000;a[i+1]:=0;j:=i;
repeat inc(j);if z[j]='*' then begin a[i]:=(a[i]mod 10000*a[j+1]mod 10000)mod 10000;a[j+1]:=0;end;until (z[j]='+')or(j>o);end;
for i:=1 to o+1 do inc(ans,a[i]);
writeln(ans mod 10000);
end. -
2014-09-08 14:10:04@
我也是呀
评测结果
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 712 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 712 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 716 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 708 KiB, score = 10
测试数据 #4: WrongAnswer, time = 0 ms, mem = 712 KiB, score = 0
测试数据 #5: WrongAnswer, time = 0 ms, mem = 708 KiB, score = 0
测试数据 #6: WrongAnswer, time = 0 ms, mem = 712 KiB, score = 0
测试数据 #7: Accepted, time = 0 ms, mem = 712 KiB, score = 10
测试数据 #8: RuntimeError, time = 15 ms, mem = 704 KiB, score = 0
测试数据 #9: RuntimeError, time = 7 ms, mem = 700 KiB, score = 0
RuntimeError, time = 52 ms, mem = 716 KiB, score = 50
代码#include <iostream>
#include <stdio.h>
#include <string.h>using namespace std;
char s[200000 + 10];
int i;
int st , sn , sum;
int flag;int main()
{
memset( s , 0 , sizeof( s ) );
while( scanf( "%s" , s ) != EOF )
{
flag = 0;
st = 0;
sn = 0;
sum = 0;
for( i = 0 ; s[i] != 0 ; i++ )
{
if( s[i] >= '0' && s[i] <= '9' )
//numeric
{
if( st == 0 )
st = s[i] - '0';
else
st = ( ( st * 10 % 10000 ) + s[i] - '0' ) % 10000;
}
else if( s[i] == '+' )
{
if( flag )
{
sn = 0;
st = 0;
flag = 0;
}
else if( sn != 0 )
{
sum += ( sn % 10000 ) * ( st % 10000 ) % 10000;
sum %= 10000;
sn = 0;
st = 0;
}
else
{
sum += ( st % 10000 );
st = 0;
sum %= 10000;
}}
else if( s[i] == '*' )
{
if( st == 0 )
flag = 1;
if( sn == 0 )
sn = st;
else
sn *= ( st % 10000 );
st = 0;
sn %= 10000;
//cout << flag;
}
}
if( flag )
;
else if( sn != 0 )
sum += ( sn % 10000 ) * ( st % 10000 ) % 10000;
else if( st != 0 )
sum += st % 10000;
sum %= 10000;
cout << sum << endl;
memset( s , 0 , sizeof( s ) );
}
return 0;
}
- 1
信息
- ID
- 1849
- 难度
- 7
- 分类
- (无)
- 标签
- 递交数
- 3592
- 已通过
- 768
- 通过率
- 21%
- 被复制
- 10
- 上传者