QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599664 | #4049. 预处理器 | _TLEer_# | 40 | 1ms | 3900kb | C++14 | 2.0kb | 2024-09-29 08:41:20 | 2024-09-29 08:41:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
string nw,tmp;
vector<string> stab,stato;
int n,stdcnt,kmp[1010],tr;
bool ck(string s,int pos){
if(pos<0)return 1;
// cout<<s<<' '<<pos<<' '<<s[pos-1]<<' '<<s[pos]<<' '<<s[pos+1]<<endl;
if(s[pos]>='a'&&s[pos]<='z')return 0;
if(s[pos]>='A'&&s[pos]<='Z')return 0;
if(s[pos]>='1'&&s[pos]<='9')return 0;
return s[pos]!='_';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie();cout.tie();
// freopen("ex_preprocessor1.in","r",stdin);
// freopen("preprocessor.out","w",stdout);
cin>>n;getline(cin,nw);
while(n--){
getline(cin,nw);
if(nw[0]=='#'){
if(nw[1]=='d'){
stdcnt++;
tr=8;
do tmp+=nw[tr]; while(nw[++tr]!=' ');
stab.emplace_back(tmp);
tr++;tmp="";
do tmp+=nw[tr]; while(nw[++tr]);
stato.emplace_back(tmp);
tmp="";
}
else if(nw[1]=='u'){
stdcnt--;
tr=7;tmp="";
do
tmp+=nw[tr];
while(nw[++tr]!='\0');
for(auto i=stab.begin(),j=stato.begin();i<stab.end();i++,j++)
if(*i==tmp){
stab.erase(i);
stato.erase(j);
break;
}
// else cout<</**i<<' '<<*/tmp<<" sdfs\n";
}
cout<<'\n';
}
else{
bool rt=false;
do{
rt=0;
for(int i=0;i<stdcnt;i++){
tmp=stab[i]+'#'+nw;
kmp[0]=0;
for(int j=1;j<tmp.size();j++){
int r=kmp[j-1];
while(tmp[j]!=tmp[r]&&r>0)
r=kmp[r-1];
if(tmp[j]==tmp[r])r++;
kmp[j]=r;
if(r==stab[i].size()&&j>stab[i].size()&&ck(tmp,j+1)&&ck(nw,j-2*stab[i].size()-1)){
if((int)(j-2*stab[i].size())<0)
nw=stato[i]+nw.substr(j-stab[i].size());
else
// cout<<nw.substr(0,j-2*stab[i].size())<<'+'<<stato[i]<<'+'<<nw.substr(j-stab[i].size())<<endl,
nw=nw.substr(0,j-2*stab[i].size())+stato[i]+nw.substr(j-stab[i].size());
// cout<<stab[i]<<' '<<nw.size()<<' '<<j<<' '<<stab[i].size()<<' '<<r<<endl;
rt=1;
tmp=stab[i]+'#'+nw;
}
}
}
}while(rt);
cout<<nw<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3564kb
input:
1 printf("Hello, world!\n");
output:
printf("Hello, world!\n");
result:
ok single line: 'printf("Hello, world!\n");'
Test #2:
score: 10
Accepted
time: 1ms
memory: 3508kb
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:
ok 5 lines
Test #3:
score: 10
Accepted
time: 1ms
memory: 3576kb
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:
ok 5 lines
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3648kb
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 B C C B B B B B B C C B B B B B B C C B B B
result:
wrong answer 5th lines differ - expected: 'C C C C C C C', found: 'B B B C'
Test #5:
score: 0
Runtime Error
input:
6 #define A A+B+C #define B b+C #define C B+c A*B*C #undef B A*B*C
output:
result:
Test #6:
score: 10
Accepted
time: 0ms
memory: 3608kb
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
Runtime Error
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 b y c W Q o x V B L R I J p i q j D X z F P X h c z T C P Q M G ?!*(\@{$.!(;!'?<(=^ R b L U V s O o l u v...
result:
Test #8:
score: 0
Wrong Answer
time: 1ms
memory: 3536kb
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 p i q j D S V j P p O g X R y T D C \)&%\<=!$(><[[./*{\ G A w r s a M c...
result:
wrong answer 4th lines differ - expected: 'g W T N h X y w A C r s \)&%\<...I J &-~?<@`](!+*(}{+?-| i q j D', found: 'g W T N h X y w A C r s \)&%\<...G U o x z P B L V I J p i q j D'
Test #9:
score: 0
Runtime Error
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 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 K U y Q g A V l X* D E e w s k H a r P S M C N 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:
Test #10:
score: 0
Wrong Answer
time: 1ms
memory: 3900kb
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 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 K U y Q g A V l V* D E e w s k H a r P S M C N 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 4th lines differ - expected: 'p V E q V* j A O x> l d a z R ...K k x D r y g S f s o Q c e T m', found: 'p V E q V* j A O N l d a z R G...K k x D r y g S f s o Q c e T m'