北大1068题
2008-10-20 19:38
155 查看
题目连接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1068
之所以写上来主要是因为自己太贪图技巧了,开始的时候一直去想数字之间的对应关系,没有想到直接模拟。浪费了不少时间。再有字符串的查找函数的第一个参数是要查找的字符,第二个参数是查找的起始下标,str.find(tar,index);
#include <iostream>
#include <string>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
int cases;
cin >> cases;
int pcode[20],wcode[20],i,j,k,l,n,t;
string str;
while(cases > 0)
{
cin >> n;
for(i = 0;i < n;++i)
cin >> pcode[i];
for(i = 0;i < pcode[0];++i)
str += "(";
str += ")";
for(i = 1;i < n;++i)
{
for(j = 0;j < pcode[i] - pcode[i - 1];++j)
str += "(";
str += ")";
}
i = l = 0;
while(true)
{
j = str.find(')',i);
i = j + 1;
if(j == -1)
break;
t = 1;
for(k = j - 1;k >= 0;--k)
{
if(str[k] == '(')
{
str[k] = ' ';
break;
}
else if(str[k] == ')')
++t;
}
wcode[l] = t;
++l;
}
for(i = 0;i < l;++i)
cout << wcode[i] << ' ';
cout << '/n';
str = "";
--cases;
}
return 0;
}
之所以写上来主要是因为自己太贪图技巧了,开始的时候一直去想数字之间的对应关系,没有想到直接模拟。浪费了不少时间。再有字符串的查找函数的第一个参数是要查找的字符,第二个参数是查找的起始下标,str.find(tar,index);
#include <iostream>
#include <string>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
int cases;
cin >> cases;
int pcode[20],wcode[20],i,j,k,l,n,t;
string str;
while(cases > 0)
{
cin >> n;
for(i = 0;i < n;++i)
cin >> pcode[i];
for(i = 0;i < pcode[0];++i)
str += "(";
str += ")";
for(i = 1;i < n;++i)
{
for(j = 0;j < pcode[i] - pcode[i - 1];++j)
str += "(";
str += ")";
}
i = l = 0;
while(true)
{
j = str.find(')',i);
i = j + 1;
if(j == -1)
break;
t = 1;
for(k = j - 1;k >= 0;--k)
{
if(str[k] == '(')
{
str[k] = ' ';
break;
}
else if(str[k] == ')')
++t;
}
wcode[l] = t;
++l;
}
for(i = 0;i < l;++i)
cout << wcode[i] << ' ';
cout << '/n';
str = "";
--cases;
}
return 0;
}
相关文章推荐
- [转载]北大,你已经无耻到了极点
- 汇编语言北大上机考试基本功训练(一)
- [普及扫盲]芙蓉JJ——红透清华北大的美女(狂晕中)
- [转帖]一个北大人的工作感悟
- 在北大校园BBS引起轰动的一篇文章
- [整理]就业寒流波及"北大"才子,当街卖肉/糖葫芦,让人惊诧.
- 北京永远是中国最好的城市(一个北大学生的感言)
- 一个北大学子毕业后的感悟[转]
- 【MVP】 Wenzhong Huang 北大硕士,微软MVP,微软嵌入式讲师,MCSE
- 消失中的北大!
- 北大组织“富豪俱乐部”,有何不可?
- 在北大校园BBS引起轰动的一篇文章
- 一个北大学生妙答日本记者
- 分词:词性标注北大标准
- 如果没有开源软件没有免费软件,这个世界会怎么样?------评[盖茨北大演讲遭遇开源人士抗议]
- 清华给美国培养工程师,北大给美国培养老婆?
- 北大ACM-题型分类
- [观点]谢中卿:北大孔博士陷入金庸崇拜
- 北大ACM题型分类
- 【MVP】 Wenzhong Huang 北大硕士,微软MVP,微软嵌入式讲师,MCSE