34 条题解
-
0剑心2014 LV 5 @ 2014-10-24 18:59:50
评测结果
编译成功测试数据 #0: Accepted, time = 0 ms, mem = 1216 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 1216 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 1220 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 1212 KiB, score = 10
测试数据 #4: Accepted, time = 15 ms, mem = 1212 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 1220 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 1216 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 1212 KiB, score = 10
测试数据 #8: Accepted, time = 62 ms, mem = 1212 KiB, score = 10
测试数据 #9: Accepted, time = 46 ms, mem = 1216 KiB, score = 10
Accepted, time = 138 ms, mem = 1220 KiB, score = 100
代码
var
i,j,k:longint;
flag:boolean;
c:char;
tot,temp:qword;
a:array[0..100000] of longint;
procedure add;
begin
inc(i);
a[i]:=temp;
temp:=0;
end;
procedure jisuan;
begin
if flag then begin
a[i-1]:=(a[i-1]*a[i]) mod 10000;
dec(i);
end;
end;
beginwhile not eoln do begin
read(c);
case c of
'+':begin
add;
jisuan;
flag:=false;
end;
'*': begin
add;
jisuan;
flag:=true;
end;
else begin
val(c,k);
temp:=temp*10+k;
end
end;
end;
inc(i);
a[i]:=temp;
tot:=0;
if flag then begin
inc(tot,a[i]*a[i-1]mod 10000);
i:=i-2;
end;
while i>0 do begin
inc(tot,a[i]);
tot:=tot mod 10000;
dec(i);
end;
writeln(tot);end.
-
02014-10-24 12:42:30@
var num:array[0..100002]of integer;
f:array[0..100001]of char;
i,ftop,ntop,log:longint; z,sum:int64;
s:ansistring; la:string;
procedure done;
var z:longint;
begin
val(la,log);
if log>10000 then log:=log mod 10000;
la:='';
if f[ftop]='*' then
begin
z:=(num[ntop]*log) mod 10000;
num[ntop]:=z;
dec(ftop);
end
else
begin
inc(ntop);
num[ntop]:=log;
end;
inc(ftop);
f[ftop]:=s[i];
end;
begin
readln(s);
for i:=1 to length(s) do
if s[i]in['*','+'] then done
else la:=la+s[i];done;
for i:=1 to ntop do
begin
inc(sum,num[i]);
if sum>10000 then sum:=sum mod 10000;
end;
writeln(sum);
end. -
02014-08-28 09:32:04@
前几次RE都是数组开小了。。。
测试数据 #0: Accepted, time = 0 ms, mem = 2516 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 2516 KiB, score = 10
测试数据 #2: Accepted, time = 15 ms, mem = 2516 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 2516 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 2516 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 2516 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 2516 KiB, score = 10
测试数据 #7: Accepted, time = 218 ms, mem = 2516 KiB, score = 10
测试数据 #8: Accepted, time = 234 ms, mem = 2520 KiB, score = 10
测试数据 #9: Accepted, time = 218 ms, mem = 2508 KiB, score = 10
#include<iostream>
#include<stack>
#include<cstring>
#define ll long long
using namespace std;
ll f11(char a,char b)
{
if(a=='+') a=0;
if(a=='*') a=1;
if(b=='+') b=0;
if(b=='*') b=1;
return a>=b;
}
int main()
{
ll a,b,y,c;
char x;
ll q=0;
char s[2000005];
while(cin>>s){
stack<ll> s1;
stack<char> f1;
c=strlen(s);
for(ll i=0;s[i];i++)
if(s[i]>='0'&&s[i]<='9')
{
q=0;
while(s[i]>='0'&&s[i]<='9')q=(s[i++]-'0'+q*10)%10000;
i--;
s1.push(q);
//s1.push(s[i]-'0');
if(!s1.empty()) if(i==(c-1)) while(!f1.empty()) {
a=s1.top();
s1.pop();
b=s1.top();
s1.pop();
x=f1.top();
if(x=='+') s1.push(((a+b)%10000));
if(x=='*') s1.push(((a*b)%10000));
f1.pop();
}
}
else{
if(f1.empty()){f1.push(s[i]);}
else{
while(!f1.empty())
{
x=f1.top();
if(f11(x,s[i]))
{
a=s1.top();s1.pop();b=s1.top();s1.pop();
if(x=='+') s1.push(((a+b)%10000));
if(x=='*') s1.push(((a*b)%10000));
f1.pop();
}
else break;
}
f1.push(s[i]);
}
}
y=s1.top();
cout<<y%10000<<endl;
}
return 0;
} -
02014-06-30 12:44:21@
代码
var b,e,n,s,l,m,g,q,j:int64;
a,x:string;
d,t:longint;
c:array[1..10000000]of int64;
o:array[1..10000000]of char;
begin
readln(a);
l:=0;
for d:=1 to length(a) do
begin
if (a[d]='*')or(a[d]='+')then
begin
s:=d-1;l:=l+1;q:=1;o[l]:=a[d];
while (a[s]<>'+')and(a[s]<>'*')and(s<>0) do
begin
val(a[s],n,t);
c[l]:=c[l]+n*q;
q:=q*10;
s:=s-1;
end;
end;
end;
d:=length(a);
l:=l+1;
q:=1;
while (a[d]<>'+')and(a[d]<>'*') do
begin
val(a[d],n,t);
c[l]:=c[l]+n*q;
q:=q*10;
d:=d-1;
end;
for d:=1 to l do
if o[d]='*' then
begin
c[d+1]:=c[d]*c[d+1];
c[d]:=0;
end;
g:=0;
for d:=1 to l do
g:=g+c[d];
g:=g mod 10000;
str(g,x);
j:=0;
a:='';
for d:=1 to length(x) do
a:=a+x[d];
val(a,g,d);
write(g);
end. -
02014-06-30 12:42:18@
var b,e,n,s,l,m,g,q,j:int64;
a,x:string;
d,t:longint;
c:array[1..10000000]of int64;
o:array[1..10000000]of char;
begin
readln(a);
l:=0;
for d:=1 to length(a) do
begin
if (a[d]='*')or(a[d]='+')then
begin
s:=d-1;l:=l+1;q:=1;o[l]:=a[d];
while (a[s]<>'+')and(a[s]<>'*')and(s<>0) do
begin
val(a[s],n,t);
c[l]:=c[l]+n*q;
q:=q*10;
s:=s-1;
end;
end;
end;
d:=length(a);
l:=l+1;
q:=1;
while (a[d]<>'+')and(a[d]<>'*') do
begin
val(a[d],n,t);
c[l]:=c[l]+n*q;
q:=q*10;
d:=d-1;
end;
for d:=1 to l do
if o[d]='*' then
begin
c[d+1]:=c[d]*c[d+1];
c[d]:=0;
end;
g:=0;
for d:=1 to l do
g:=g+c[d];
g:=g mod 10000;
str(g,x);
j:=0;
a:='';
for d:=1 to length(x) do
a:=a+x[d];
val(a,g,d);
write(g);
end. -
02013-12-19 21:20:52@
评测结果
编译成功Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling foo.pas
Linking foo.exe
45 lines compiled, 0.1 sec , 27648 bytes code, 1628 bytes data测试数据 #0: Accepted, time = 0 ms, mem = 4648 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 4652 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 4652 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 4652 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 4648 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 4648 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 4648 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 4652 KiB, score = 10
测试数据 #8: Accepted, time = 31 ms, mem = 4648 KiB, score = 10
测试数据 #9: Accepted, time = 140 ms, mem = 4648 KiB, score = 10
Accepted, time = 171 ms, mem = 4652 KiB, score = 100
代码
var
a:array[0..1000000]of longint;
ch:char;
i,s:longint;
ans:qword;procedure readin;
begin
s:=1;
while not eoln do
begin
read(ch);
if (ch<>'+') and (ch<>'*') then
a[s]:=(a[s]*10+ord(ch)-ord('0')) mod 10000;
if ch='*' then
begin
inc(s);
a[s]:=-1;
inc(s);
end;
if ch='+' then
begin
inc(s);
a[s]:=-2;
inc(s);
end;
end;
end;begin
readin;
for i:=1 to s do
if a[i]=-1 then
begin
a[i]:=((a[i-1] mod 10000)*(a[i+1] mod 10000)) mod 10000;
a[i-1]:=a[i];
a[i+1]:=a[i];
end;
ans:=0;
for i:=1 to s do
if a[i]=-2 then ans:=(ans+a[i-1]) mod 10000;
ans:=(ans+a[s]) mod 10000;
if ans<10000 then writeln(ans)
else writeln(ans mod 10000);
end. -
02013-12-06 20:58:09@
我擦,提交的时候选错语言了。。Wa了一次
-
02013-11-29 13:53:26@
var i,j,len,p,a,b,sum,lens:longint;
s,s1,s2,ans:ansistring;procedure calc;
begin
p:=pos('*',s);
while p<>0 do
begin
len:=length(s);
for i:=p-1 downto 2 do
if (s[i]='+')or(s[i]='*') then break;
s1:=s;
s1:=copy(s1,i+1,p-i-1);
lens:=length(s1);
if lens>4 then
delete(s1,1,lens-4);for j:=p+1 to len do
if (s[j]='+')or(s[j]='*') then break;
s2:=s;
s2:=copy(s2,p+1,j-p-1);
lens:=length(s2);
if lens>4 then
delete(s2,1,lens-4);val(s1,a);
val(s2,b);
sum:=a*b;
str(sum,ans);
lens:=length(ans);
if lens>4 then
delete(ans,1,lens-4);delete(s,i+1,j-i-1);
insert(ans,s,i+1);
p:=pos('*',s);
end;
p:=pos('+',s);
while p<>0 do
begin
len:=length(s);
s1:=s;
s1:=copy(s1,1,p-1);
for j:=p+1 to len do
if s[j]='+' then break;
s2:=s;
if j=len then
begin
s2:=copy(s2,p+1,len-p);
val(s1,a);
val(s2,b);
sum:=a+b;
str(sum,s);
end
else
begin
s2:=copy(s2,p+1,j-p-1);
val(s1,a);
val(s2,b);
sum:=a+b;
str(sum,ans);
delete(s,1,j-1);
insert(ans,s,1);
end;
p:=pos('+',s);
end;
len:=length(s);
if len>4 then
begin
delete(s,1,len-4);
len:=length(s);
end;
val(s,a);
a:=a-2;
str(a,s);
end;begin
assign(input,'expr.in');
reset(input);
readln(s);
close(input);
s:='1+'+s+'+1';
calc;
assign(output,'expr.out');
rewrite(output);
write(s);
close(output);
end. -
02013-11-18 21:27:51@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int sum=0,tmp1=1,tmp2=0;
char str;
int main()
{
while(scanf("%c",&str)!=EOF)
{
if(str=='+'){
sum=(sum+tmp1*tmp2)%10000;
tmp1=1; tmp2=0;
}
else if(str=='*'){
tmp1=(tmp1*tmp2)%10000;
tmp2=0;
}
else tmp2=(tmp2*10+(str-'0'))%10000;
}
printf("%d",(sum+tmp1*tmp2)%10000);
return 0;
}
考试的时候把这道题想麻烦了,没得什么分。其实这道题就是输入一位然后接着按规则处理。 -
-12017-07-16 15:38:05@
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
char a[10000000];
char fu[10000000];//符号栈
char num[10000000];//存储数组
long long shu[10000000];//运算栈
int main()
{
int w=0;
do{
a[w]=getchar();
w++;
}while(a[w-1]!='\n');
long long futop=0;//栈顶指针
long long numtop=0;
long long top=0;
long long len=strlen(a),i=0;
for(i=0;i<=len-1;i++)
{
if(a[i]<='9'&&a[i]>='0')
num[++numtop]=a[i];
else
{
num[++numtop]=' ';//先预留出空格
//再检查优先级别
if(a[i]=='*') fu[++futop]='*';
else
{
//加号前面的所有符号要出栈
while(futop>0)
num[++numtop]=fu[futop--];
fu[++futop]='+';
}
}
}
while(futop>0) num[++numtop]=fu[futop--];
for(i=1;i<=numtop;i++)
{
if(num[i]==' ') continue;
long long h=0;
bool flag=0;
while(num[i]>='0'&&num[i]<='9')
{
h=(h*10+num[i]-48)%10000;
i++;
flag=1;
}
if(flag==1) shu[++top]=h;
if(num[i]=='+'||num[i]=='*')
{
int k=shu[top];
int h=shu[--top];
if(num[i]=='+') shu[top]=(h+k)%10000;
else shu[top]=(h*k)%10000;
}
}
cout<<shu[1]%10000;
return 0;
} -
-12016-11-10 20:59:43@
人生苦短
python
print eval(raw_input()) % 10000
-
-12016-10-19 13:13:17@
#include<bits/stdc++.h>
using namespace std;
char a[5000005];
int x[5000005];
int main()
{
int i,j,k,l,n,m,v=1,z=0,num;
cin>>a;
n=strlen(a);
a[n]='+';
for(i=0;i-1<n;i++) {
k=a[i];
l='+';//43
m='*';//42
if(k==l) x[i]=314159;
else if(k==m) x[i]=314158;
else {
x[i]=k-'0';
num=x[i];
x[i]=0;
while(1){
if(a[i+v]>='0' && a[i+v]<='9') {
x[i+v]=a[i+v]-'0';
num=num*10+x[i+v];
num%=10000;
x[i+v]=0;
v++,z++;
}
else {
x[i+z]=num;
i+=z;
v=1,z=0;
break;
}
}
}
}
z=0;
for(i=0;i<n+1;i++){
if(z>0&&(x[i]==314158||x[i]==314159)) {
x[i-1]*=x[z-1];
x[z-1]=x[z]=0;
x[i-1]%=10000;
z=0;
}
if(x[i]==314158) {
z=i;
}
}
z=0;
for(i=0;i-1<n;i++){
if(z>0&&x[i]==314159) {
x[i-1]+=x[z-1];
x[z-1]=x[z]=0;
x[i-1]%=10000;
z=0;
}
if(x[i]==314159) {
z=i;
}
}
cout<<x[n-1]%10000<<endl;
return 0;
} -
-12016-10-16 16:08:25@
var x,y,z,i:longint;
s:ansistring;
begin
x:=0;
y:=1;
z:=0;
readln(s);
for i:=1 to length(s) do
begin
if s[i]='+' then
begin
y:=(y*z) mod 10000;
z:=0;
x:=(x+y) mod 10000;
y:=1;
end
else if s[i]='*' then
begin
y:=(y*z) mod 10000;
z:=0;
end
else
z:=z*10+ord(s[i])-48;
end;
y:=(y*z) mod 10000;
x:=(x+y) mod 10000;
writeln(x);
end.
水水水水水水水水水水水水水水水水水水水水水水水水
只要一个一个判断即可 -
-12016-07-09 12:48:01@
#include <cstdio>
using namespace std;
const int MOD=10000;
template<class TYPE>
class Stack{
public:
TYPE e[100005];
int tp;
Stack()
{
tp=0;
}
void push(TYPE x)
{
e[tp++]=x;
}
void pop()
{
tp--;
}
TYPE top()
{
return e[tp-1];
}
bool empty()
{
return tp==0;
}
};
int main()
{
Stack<int> it;
Stack<char> op;
int e;
char ch;
while(scanf("%d%c",&e,&ch)&&ch!='\n')
{
e%=MOD;
it.push(e);
if(op.empty())
{
op.push(ch);
}
else
{
char tp=op.top();
if(ch=='*'&&tp=='+')
{
op.push(ch);
}
else
{
op.pop();
int y=it.top();it.pop();
int x=it.top();it.pop();
int z;
if(tp=='+') z=x+y;
else z=x*y;
z%=MOD;
it.push(z);
op.push(ch);
}
}
}
it.push(e);
while(!op.empty())
{
char ch=op.top();op.pop();
int y=it.top();it.pop();
int x=it.top();it.pop();
int z;
if(ch=='+') z=x+y;
else z=x*y;
z%=MOD;
it.push(z);
}
int res=it.top();
res%=MOD;
printf("%d\n",res);
return 0;
}
信息
- ID
- 1849
- 难度
- 7
- 分类
- (无)
- 标签
- 递交数
- 3592
- 已通过
- 768
- 通过率
- 21%
- 被复制
- 10
- 上传者