hdu 1274 展开字符串
2013-02-26 17:05
337 查看
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1274
一开始solve没有返回位置,然后递归的时候就出错了。。。
STL特别好用。。。
View Code
http://acm.hdu.edu.cn/showproblem.php?pid=1274
一开始solve没有返回位置,然后递归的时候就出错了。。。
STL特别好用。。。
View Code
#include<iostream> #include<string> using namespace std; int solve(string &str,string &restr,int pos){ int len=str.length(); while(pos<len){ //是字母 if(str[pos]>='a'&&str[pos]<='z'){ restr.push_back(str[pos]); }else if(str[pos]>='0'&&str[pos]<='9'){ //是数字 int count=0; while(pos<len&&str[pos]>='0'&&str[pos]<='9'){ count=10*count+str[pos]-'0'; pos++; } //后面是字母 if(str[pos]>='a'&&str[pos]<='z'){ for(int i=1;i<=count;i++){ restr.push_back(str[pos]); } }else if(str[pos]=='('){ //后面是括号 string temp; pos=solve(str,temp,pos+1); for(int i=1;i<=count;i++){ restr.append(temp); //追加 } } }else if(str[pos]=='('){ //是括号 string temp; pos=solve(str,temp,pos+1); restr.append(temp); }else if(str[pos]==')'){ break; } pos++; } return pos; } int main(){ int n; scanf("%d",&n); while(n--){ string str,restr; cin>>str; solve(str,restr,0); cout<<restr<<endl; } return 0; }
相关文章推荐
- HDU 1274 展开字符串 (递归+string类)
- HDU - 1274 展开字符串
- HDU - 1274: 展开字符串(递归,栈模拟)
- HDU 1274 展开字符串(递归)
- hdu 1274 展开字符串 (简单dfs)
- HDU 1274 展开字符串
- hdu 1274展开字符串(搜索)
- HDU 1274(展开字符串)
- HDU 1274 展开字符串
- hdu 1274 展开字符串 - 栈
- HDU-1274-展开字符串(dfs分段字符串处理)
- hdu 1274 展开字符串
- hdu 1274 展开字符串
- HDU 1274(展开字符串)
- CSU-ACM2017暑期训练3-递推与递归 G - 展开字符串 HDU - 1274
- hdu 1274 展开字符串 栈 stack 处理
- hdu 1274展开字符串(用栈来实现的)
- hdu 1274 展开字符串
- HDU 1274 展开字符串
- (HDU - 1274 )展开字符串