栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1172 Alternatives

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1172 Alternatives

#include <cstdio>#include <cstring>#include <string>#include <set>#include <iostream>using namespace std;char stk[1000][280];char hd[280], var[280], s[280];set<string> ST;int main(void){    int T, i, j, pre, L, R;    scanf("%d", &T);    getchar();    while(T--)    {        ST.clear();        getchar();        gets(s);        int ansCnt = 0;        int top = 0;        strcpy(stk[top++], s);        while(top)        { -- top; strcpy(hd, stk[top]); if(strchr(hd, '[') == NULL) {     ST.insert(string(hd));     continue; } int len = strlen(hd); L = strchr(hd, '[') - hd; int cnt = 0; for(i = L+1; i < len; ++i) {     if(cnt == 0 && hd[i] == ']') break;     if(hd[i] == '[') ++cnt;     if(hd[i] == ']') --cnt; } R = i; strncpy(s, hd, L); strncpy(var, hd+L+1, R-L-1); j = R-L-1; pre = cnt = 0; for(i = 0; i < j; ++i) {     if(var[i] == '[') ++cnt;     if(var[i] == ']') --cnt;     if(cnt == 0 && var[i] == '|')     {         strncpy(s+L, var+pre, i-pre);         strncpy(s+L+i-pre, hd+R+1, len-R);         strcpy(stk[top++], s);         pre = i+1;     } } strncpy(s+L, var+pre, j-pre); strncpy(s+L+j-pre, hd+R+1, len-R); strcpy(stk[top++], s);        }        for(set<string>::iterator it = ST.begin(); it != ST.end(); ++it) cout << *it << endl;        if(T) putchar('n');    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371515.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号