QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649781#4049. 预处理器Mr_Az20 24ms3884kbC++142.1kb2024-10-18 10:18:302024-10-18 10:18:30

Judging History

你现在查看的是最新测评结果

  • [2024-10-18 10:18:30]
  • 评测
  • 测评结果:20
  • 用时:24ms
  • 内存:3884kb
  • [2024-10-18 10:18:30]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<list>
#define rint register int
#define mem(a,b) memset(a,b,sizeof a)
#define lowbit(x) (x&-x)
#define debug(a,b) cout<<"line"<<__LINE__<<":"<<a<<" = "<<b<<endl;
#define eb emplace_back
#define pb push_back
#define read raed
#define int long long
#define ls (p<<1)
#define rs (p<<1|1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const ll INF=1e18;

template<typename T>
void read(T &x){
    x=0;int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
    while(isdigit(c)){x=x*10+c-'0';c=getchar();}
    x*=f;
}
template<typename T,typename ... Args>
void read(T &x, Args &... y){read(x);read(y...);}
int n;
string s;
map<string,string> Define;
map<string,bool> work;
inline bool is(char ch){
	return (isalpha(ch)||isdigit(ch)||ch=='_');
}
inline string calc(string s){
	cerr<<s<<" in\n";
	string res="",t="";
	if(Define[s]!="") return calc(Define[s]);
	for(rint i=0;i<s.size();i++){
		if(is(s[i])) t+=s[i];
		else{
			if((Define.find(t)!=Define.end()&&Define[t]!="")&&!work[t]){
				work[t]=1;
				res+=calc(Define[t]);
				work[t]=0;
			}
			else res+=t;
			res+=s[i];
			t="";
		}cerr<<i<<":"<<t<<endl;
	}
	if((Define.find(t)!=Define.end()&&Define[t]!="")&&!work[t]){
		work[t]=1;
		res+=calc(Define[t]);
		work[t]=0;
	}
	else res+=t;
	cerr<<res<<" out\n";
	return res;
}
signed main(){
	read(n);
	for(rint i=1;i<=n;i++){
		string now="";
		getline(cin,s);
		if(s[0]=='#'){
			if(s[1]=='d'){
				string t1="",t2="";
				int j=8;
				while(s[j]!=' '&&j<s.size()) t1+=s[j],j++;
				j++;
				while(s[j]!=' '&&j<s.size()) t2+=s[j],j++;
				Define[t1]=t2;
				cerr<<t1<<"|"<<t2<<"|"<<endl;
			}
			else{
				string t1="";
				int j=7;
				while(s[j]!=' '&&j<s.size()) t1+=s[j],j++;
				cerr<<t1<<"|"<<endl;
				Define[t1]="";
			}
		}
		else{
			cout<<calc(s)<<endl;
		}
	}
	return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 3620kb

input:

1
printf("Hello, world!\n");

output:

printf("Hello, world!\n");

result:

ok single line: 'printf("Hello, world!\n");'

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 3788kb

input:

5
#define PI 3.14159
#define E 2.71828
std::cout << PI * r * r << std::endl;
std::cout << log10(x) / log10(E) << std::endl;
std::cout << "E^(PI * i) + 1 = 0" << std::endl;

output:

std::cout << 3.14159 * r * r << std::endl;
std::cout << log10(x) / log10(2.71828) << std::endl;
std::cout << "2.71828^(3.14159 * i) + 1 = 0" << std::endl;

result:

wrong answer 1st lines differ - expected: '', found: 'std::cout << 3.14159 * r * r << std::endl;'

Test #3:

score: 0
Wrong Answer
time: 1ms
memory: 3556kb

input:

5
#define A abc
#define B hij
A B AB BA B A
#undef A
A B AB BA B A

output:

abc hij AB BA hij abc
A hij AB BA hij A

result:

wrong answer 1st lines differ - expected: '', found: 'abc hij AB BA hij abc'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

9
#define A B B
A B C
C B A
#define B C C
A B C
C B A
#define C [a, b, c]
A B C
C B A

output:

B B C
C B B
C C C
C C C
[a, [a, [a,
[a, [a, [a,

result:

wrong answer 1st lines differ - expected: '', found: 'B B C'

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 3588kb

input:

6
#define A A+B+C
#define B b+C
#define C B+c
A*B*C
#undef B
A*B*C

output:

A+b+B+c+b+C+c*b+B+c*b+C+c
A+B+B+c*B*B+c

result:

wrong answer 1st lines differ - expected: '', found: 'A+b+B+c+b+C+c*b+B+c*b+C+c'

Test #6:

score: 10
Accepted
time: 4ms
memory: 3884kb

input:

100
8czu(!@iNcuVcs9Zu3/a.$Fo{Fij<4.'Y}JZ:6>2%evBhvjA7IItz`85q'pJ 80"<+vdDzt`?D9L\Ryx0y2[Lu Viek6-NfJ X}=
b&"Yz8kOQ{?yVq\>C85o*Y,XaEb^?;Cf?{iTg**mSZy?NtY'sD 9PWlvF3vug7v\=gw_um^1S,.rjONR'!~jLF=xrQNAx]P=Ze ;
}^<pTuLfJ~y,QN{ 0&oB}2Y)f2V=o|hr3!wl@x36N2X^t&wL!CD)gR  guy^??Io;%5~9a/C_`mkk0z4&t7yT\<iNAa+7y...

output:

8czu(!@iNcuVcs9Zu3/a.$Fo{Fij<4.'Y}JZ:6>2%evBhvjA7IItz`85q'pJ 80"<+vdDzt`?D9L\Ryx0y2[Lu Viek6-NfJ X}=
b&"Yz8kOQ{?yVq\>C85o*Y,XaEb^?;Cf?{iTg**mSZy?NtY'sD 9PWlvF3vug7v\=gw_um^1S,.rjONR'!~jLF=xrQNAx]P=Ze ;
}^<pTuLfJ~y,QN{ 0&oB}2Y)f2V=o|hr3!wl@x36N2X^t&wL!CD)gR  guy^??Io;%5~9a/C_`mkk0z4&t7yT\<iNAa+7y(ZOa...

result:

ok 100 lines

Test #7:

score: 0
Wrong Answer
time: 24ms
memory: 3604kb

input:

100
#define a ?!*(\@{$.!(;!'?<(=^
V X o i C I H p M A e L O F P x z h b T K s l t u Q E G m d R D c q J w N y f g U n j r v B S k W a
#define b >'[&-~?<@`](!+*(}{+
h g S l A T r N O M C k a w U G H s m E t n v f u e d K b y c W Q o x V B L R I J p i q j D X z F P
#define c }{);'|{*?>&\<];!+!|
X h c ...

output:

V X o i C I H p M A e L O F P x z h b T K s l t u Q E G m d R D c q J w N y f g U n j r v B S k W ?!*(\@{$.!(;!'?<(=^
h g S l A T r N O M C k ?!*(\@{$.!(;!'?<(=^ w U G H s m E t n v f u e d K >'[&-~?<@`](!+*(}{+ y c W Q o x V B L R I J p i q j D X z F P
X h }{);'|{*?>&\<];!+!| z T C P Q M G ?!*(\@{$...

result:

wrong answer 1st lines differ - expected: '', found: 'V X o i C I H p M A e L O F P ...r v B S k W ?!*(\@{$.!(;!'?<(=^'

Test #8:

score: 0
Wrong Answer
time: 4ms
memory: 3640kb

input:

100
#define b \)&%\<=!$(><[[./*{\
o p R a x m V i F H O X J e K d z Q C G b E M s l t u A W T I N h D c q L w P y f g U n j r v B S k
#define p &-~?<@`](!+*(}{+?-|
g W T N h X y w A C r s b l k a S Q K E m c t n v M R u e H O d f F G U o x z P B L V I J p i q j D
#define W '|{*?>&\<];!+!|{^+"
S V j ...

output:

o p R a x m V i F H O X J e K d z Q C G \)&%\<=!$(><[[./*{\ E M s l t u A W T I N h D c q L w P y f g U n j r v B S k
g W T N h X y w A C r s \)&%\<=!$(><[[./*{\ l k a S Q K E m c t n v M R u e H O d f F G U o x z P B L V I J &-~?<@`](!+*(}{+?-| i q j D
S V j P &-~?<@`](!+*(}{+?-| O g X R y T D C \)...

result:

wrong answer 1st lines differ - expected: '', found: 'o p R a x m V i F H O X J e K ...c q L w P y f g U n j r v B S k'

Test #9:

score: 0
Wrong Answer
time: 7ms
memory: 3872kb

input:

100
#define b X*
E x X l q u r h J t j H P S D O d v U e C k Q w M y a z V s F K A m N G W n T b c B L f I R g i o p
#define N T>
p V E q b j A O N l d a z R G J C i X P I h F W B t U u v L H M n w K k x D r y g S f s o Q c e T m
#define P X&
K U y Q g A V l b D E e w s k H a r P S M C N m c t n v O...

output:

E x X l q u r h J t j H P S D O d v U e C k Q w M y a z V s F K A m N G W n T X* c B L f I R g i o p
p V E q X* j A O T> l d a z R G J C i X P I h F W B t U u v L H M n w K k x D r y g S f s o Q c e T m
K U y Q g A V l X* D E e w s k H a r X& S M C T> m c t n v O T u j h d f F G W o x z R B L X I J ...

result:

wrong answer 1st lines differ - expected: '', found: 'E x X l q u r h J t j H P S D ... G W n T X* c B L f I R g i o p'

Test #10:

score: 0
Wrong Answer
time: 15ms
memory: 3848kb

input:

100
#define b V*
E x X l q u r h J t j H P S D O d v U e C k Q w M y a z V s F K A m N G W n T b c B L f I R g i o p
#define N x>
p V E q b j A O N l d a z R G J C i X P I h F W B t U u v L H M n w K k x D r y g S f s o Q c e T m
#define P D&
K U y Q g A V l b D E e w s k H a r P S M C N m c t n v O...

output:

E x X l q u r h J t j H P S D O d v U e C k Q w M y a z V s F K A m N G W n T V* c B L f I R g i o p
p V E q V* j A O x> l d a z R G J C i X P I h F W B t U u v L H M n w K k x D r y g S f s o Q c e T m
K U y Q g A V l V* D E e w s k H a r D& S M C x> m c t n v O T u j h d f F G W o x z R B L X I J ...

result:

wrong answer 1st lines differ - expected: '', found: 'E x X l q u r h J t j H P S D ... G W n T V* c B L f I R g i o p'