记录编号 47162 评测结果 AAAAAAAAAA
题目名称 [NOIP 2010冲刺十三]外星密码 最终得分 100
用户昵称 Gravatar怡红公子 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2012-10-30 23:20:38 内存使用 3.28 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstring>
  3. #include<fstream>
  4. using namespace std;
  5. ifstream fin("passworda.in");
  6. ofstream fout("passworda.out");
  7.  
  8. string Work(string s,int l,int r){
  9. if(l>r) return "";
  10. int suml=0,sumr=0,i,tot=0;
  11. string ans="";string s1="",s2="";
  12. while(s[l]<='9'&&s[l]>='0') tot=tot*10+s[l]-'0',l++;if(tot==0) tot=1;
  13. if(s[l]<='Z'&&s[l]>='A')
  14. {
  15. while(s[l]<='Z'&&s[l]>='A') s1+=s[l],l++;
  16. if(l>r) {for(i=1;i<=tot;++i) ans+=s1; return ans;}
  17. }
  18. for(i=l;i<=r;++i) {if(s[i]=='[') suml++;else if(s[i]==']') sumr++;if(suml==sumr) break;}
  19. s1+=Work(s,l+1,i-1);s2=Work(s,i+1,r);
  20. for(int i=1;i<=tot;++i) ans+=s1+s2;
  21. return ans;
  22. }
  23.  
  24. int main()
  25. {
  26. string s;
  27. fin>>s;
  28. s="1["+s+"]";
  29. string ans="";
  30. ans=Work(s,0,s.size()-1);
  31. fout<<ans<<endl;
  32. // system("pause");
  33. return 0;
  34. }