UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211768#53. evalcmx100105ms1260kbC++3.8kb2024-09-27 02:03:322024-09-27 02:03:34

answer

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define debug(x) cerr << #x << " = " << x << endl
#define fir first
#define sec second
#define mod 998244353
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef pair<double,double> pdd;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
const int N = 1e6 + 10;
inline int read() {
    int x = 0 , fl = 0;
    char c = getchar();
    while (!isdigit(c))
        fl |= c == '-' , c = getchar();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + c - '0', c = getchar();
    return fl ? -x : x;
}
inline void write(int x) {
    if (!x) {
        ptc('0');
        return;
    }
    if (x < 0) ptc('-') , x = -x;
    int dg[20], len = 0;
    while (x)
        dg[len++] = x % 10, x /= 10;
	while (len--)
        ptc(dg[len] + '0');
}
inline void writeln(int x) {
    write(x);
    ptc('\n');
}
inline int add(int x, int y, int p = mod) {
    x += y;
    if (x >= p)
        x -= p;
    return x;
}
inline int sub(int x, int y, int p = mod) {
    x -= y;
    if (x < 0)
        x += p;
    return x;
}
inline int qpow(int x, int y, int p = mod) {
    int res = 1;
    while (y) {
        if (y & 1)
            res = 1ll * res * x % p;
        x = 1ll * x * x % p;
        y >>= 1;
    }
    return res;
}
int n;
string s;
map <char,ll> values,exceed;

ll ieto(string s,int st){
	ll ans = 0;
	for (int i = st;i < s.length() && isdigit(s[i]);i++){
		ans = ans * 10ll + s[i]-'0';
	}
	return ans;
}
void solve_basic(string s){
	char left_char = s[0];
	int oper = (s[1] == '+') ;
	ll right_char = 0;
	if (isdigit(s[2 + oper])){
		right_char = ieto(s , 2 + oper);
	}else{
		right_char = values[s[2 + oper]];
	}
	values[left_char] = values[left_char] * oper + right_char;

	if (oper == 0){
		if (isdigit(s[2 + oper])){
			exceed[left_char] = (values[left_char] >= 1e9);
		}else{
			exceed[left_char] = exceed[s[2 + oper]];	
		}
	}
	else{
		if (values[left_char] >= 1e9 || exceed[left_char]){
			exceed[left_char] = 1;	
		}else{
			if (!isdigit(s[2 + oper])){
				exceed[left_char] = exceed[s[2 + oper]];	
			}else{
				exceed[left_char] = 0;	
			}
		}
	}
	values[left_char] %= 1000000000ll;
	
}

vector<string> stav;
void dfs(int x){
	if (x == stav.size() - 1){
		solve_basic(stav[x]);
		return;
	}else{
		string s = stav[x];
		ll& i = values[s[4]];
		ll L , R , t = 6;while (s[t] != ',') t++;
		int flag = 0;
		if (isdigit(s[6])){
			L = ieto(s , 6);
		}else{
			L = values[s[6]];
			flag |= exceed[s[6]];
		}
		
		if (isdigit(s[t + 1])){
			R = ieto(s , t + 1);
		}else{
			R = values[s[t + 1]];
			flag |= exceed[s[t + 1]];
		}
		if(L>R) R+=1000000000;
		exceed[s[4]] = flag;
		i = L;
		while (i <= R){
			dfs(x + 1);
			if (i + 1 > R) break;
			else i += 1;
		}
	}
}
void print(char s){
	if (exceed[s]){
		printf("%c=...%09lld\n",s,values[s]%1000000000ll);
	}else{
		
		printf("%c=%lld\n",s,values[s]);
	}
}
int main(){
	for (char i = 'A';i <= 'Z';i++){
		values[i] = 0; 
		exceed[i] = 0; 
	}
//	int g = 5;
	while (getline(cin , s)){
//		cout<<s;
//		g--;if (g==0){cout<<endl;g=5;}
		if (s[0] != 'f'){ // not for 
			solve_basic(s);
		}else{
			stav.clear();
			for (int i = 0;i < s.length();i++){
				if (s[i] == 'f'){
					int j = i;
					while (s[j] != ')') j++;
					stav.push_back(s.substr(i , j - i + 1));
					i = j;
				}else{
					stav.push_back(s.substr(i , s.length() - i));
					break;
				}
			}
//			for (string ss: stav) cout<<ss<<endl;
			dfs(0);
		}
	
	}	
	for (char i = 'A';i <= 'Z';i++){
			if (values[i] || exceed[i]){
				print(i);
			}
		}
	return 0;
}


详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1252kb

input:

O=1

output:

O=1

result:

ok single line: 'O=1'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1256kb

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: 4ms
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: 9ms
memory: 1260kb

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: 32ms
memory: 1256kb

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: 13ms
memory: 1256kb

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: 47ms
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