ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#178832 | #53. eval | 2023jjezltx | 100 | 133ms | 1260kb | C++11 | 1.7kb | 2023-08-02 16:51:17 | 2023-08-02 16:51:18 |
answer
#include <bits/stdc++.h>
#define ll long long
#define dou double
using namespace std;
string s;
bool ok[1005];
struct NUM{
bool yc;
ll num;
bool operator < (const NUM t) const{
if(t.yc && (!yc))return 1;
else if(yc && (!t.yc))return 0;
return num != t.num;
}
}num[1005];
struct FOR{
ll id;
NUM beg,end;
};
NUM tnum(char s){
if(!isdigit(s)){
ok[s] = 1;
return num[s];
}
return {0,s - '0'};
}
bool find_for(string s){
if(s.length() < 10)return 0;
if(s[0] == 'f' && s[1] == 'o' && s[2] == 'r')
return 1;
return 0;
}
FOR check_for(string s){
FOR ans;
ans.id = s[4];
ans.beg = tnum(s[6]);
ans.end = tnum(s[8]);
return ans;
}
bool find_jd(string s){
if(s.length() < 4)return 0;
if(s[1] == '+' && s[2] == '=')return 1;
return 0;
}
bool find_dy(string s){
if(s.length() < 3)return 0;
if(s[1] == '=')return 1;
return 0;
}
void dfs(string s){
if(s == "")return;
if(find_for(s)){
FOR For = check_for(s);
ok[For.id] = 1;
for(num[For.id] = For.beg;num[For.id] < For.end;){
dfs(s.substr(10,s.length() - 10));
num[For.id].num++;
if(num[For.id].num > 999999999ll){
num[For.id].num %= 1000000000ll;
num[For.id].yc = 1;
}
}dfs(s.substr(10,s.length() - 10));
return;
}
if(find_jd(s)){
NUM jia = tnum(s[3]);
num[s[0]].num += jia.num;
ok[s[0]] = 1;
if(num[s[0]].num > 999999999ll || jia.yc){
num[s[0]].num %= 1000000000ll;
num[s[0]].yc = 1;
}
return;
}
if(find_dy(s)){
ok[s[0]] = 1;
num[s[0]] = tnum(s[2]);
}
}
main(){
while(cin >> s)dfs(s);
for(ll i = 'A';i <= 'Z';i++)
if(ok[i] && (num[i].num || num[i].yc)){
if(num[i].yc)printf("%c=...%09lld\n",i,num[i].num);
else printf("%c=%ld\n",i,num[i].num);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
O=1
output:
O=1
result:
ok single line: 'O=1'
Test #2:
score: 10
Accepted
time: 1ms
memory: 1248kb
input:
C=6 B=B A=3 B=A A=0 C=C B=C C=6 B=B A=B Z=9 Y=0 I=J J=K K=L L=A L=3 A=L B=A B=B C=B C=C B=C C=0 A=B ...
output:
A=3 B=3 I=3 J=3 K=3 L=3 Z=9
result:
ok 7 lines
Test #3:
score: 10
Accepted
time: 0ms
memory: 1252kb
input:
X+=9
output:
X=9
result:
ok single line: 'X=9'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1252kb
input:
C=6 B+=B A=3 B=A A=0 C=C B=C C=6 B=B A+=B Z=9 Y+=0 I+=J J+=K K=L L=A L=3 A=L B+=A B+=B C+=B C+=C B+=...
output:
A=405 B=3234 C=1620 I=3 J=3 K=6 L=3 Z=9
result:
ok 8 lines
Test #5:
score: 10
Accepted
time: 0ms
memory: 1252kb
input:
for(I,A,6)S+=I
output:
I=6 S=21
result:
ok 2 lines
Test #6:
score: 10
Accepted
time: 2ms
memory: 1252kb
input:
for(I,A,6)S+=I A=3 for(I,A,6)S+=I for(I,A,A)S+=I for(I,A,6)T=9 A=1 B=0 for(J,0,9)B+=A A=B B=0 for(J,...
output:
A=10000 B=10000 I=6 J=10000 K=10000 L=10000 S=42 T=9 X=150025001 Y=10001 Z=50005000
result:
ok 11 lines
Test #7:
score: 10
Accepted
time: 15ms
memory: 1248kb
input:
for(A,0,9)for(B,0,A)for(C,B,A)for(D,B,C)for(E,D,C)for(F,D,E)for(G,F,E)for(H,F,G)for(I,H,G)Z+=I
output:
A=9 B=9 C=9 D=9 E=9 F=9 G=9 H=9 I=9 Z=218790
result:
ok 10 lines
Test #8:
score: 10
Accepted
time: 44ms
memory: 1248kb
input:
for(A,0,9)for(B,0,A)for(C,B,A)for(D,B,C)for(E,D,C)for(F,D,E)for(G,F,E)for(H,F,G)for(I,H,G)Z+=1 for(A...
output:
A=9 B=9 C=9 D=9 E=9 F=9 G=9 H=9 I=9 X=9 Y=218790 Z=48620
result:
ok 12 lines
Test #9:
score: 10
Accepted
time: 15ms
memory: 1248kb
input:
for(A,3,7)for(B,2,A)for(C,B,8)for(D,1,C)for(E,D,C)for(F,D,9)for(G,0,E)Z+=G
output:
A=7 B=7 C=8 D=8 E=8 F=9 G=8 Z=214641
result:
ok 8 lines
Test #10:
score: 10
Accepted
time: 56ms
memory: 1260kb
input:
Z+=1 for(I,0,9)for(J,I,9)for(K,I,J)Z+=Z I=0 J=0 K=0 A=1 for(X,0,9)B+=A for(X,0,9)C+=B for(X,0,9)D+=C...
output:
A=1 B=10 C=100 D=1000 E=10000 F=100000 G=1000000 H=10000000 I=100000000 J=...000000000 K=...00000000...
result:
ok 24 lines