poj1056
来源:互联网 发布:语言算法的复杂性 编辑:程序博客网 时间:2024/06/07 07:10
一次AC
1.需要注意文件结束符的判断
cin>>s,当遇到文件结束符时cin返回0
2.对于codeSet中的每个串,判断它是不是那些比它长的串的前缀子串即可。用substr函数返回前缀子串。
//Memory: 196KTime: 0MS//Language: C++Result: Accepted #include<iostream> #include<vector> #include<string> using namespace std; int main() { unsigned setNum; vector<string> codeSet; string s; bool flag; int i,j; setNum = 0; while(1) { flag = false; ++setNum; while(1) { if(cin>>s == 0)//读入文件结束符时,cin返回0,程序结束 return 0; if(s.compare("9")==0) break; codeSet.push_back(s); } for(i=0; i<codeSet.size(); ++i) { for(j=i+1; j<codeSet.size(); ++j) { if(codeSet[i].size()<codeSet[j].size()) { string sub=codeSet[j].substr(0,codeSet[i].size()); if(codeSet[i].compare(sub)==0) { flag = true; break; } } } if(flag) break; } if(flag) cout<<"Set "<<setNum<<" is not immediately decodable"<<endl; else cout<<"Set "<<setNum<<" is immediately decodable"<<endl; codeSet.clear(); } return 0; }
- poj1056
- Poj1056
- POJ1056
- POJ1056 IMMEDIATE DECODABILITY
- poj1056(字典树)
- POJ1056 IMMEDIATE DECODABILITY【数据结构】
- POJ1056 Runtime Error
- POJ1056 - IMMEDIATE DECODABILITY - 二叉树
- POJ1056 IMMEDIATE DECODABILITY(Trie树)
- ZOJ1808 POJ1056 HDU1305 Immediate Decodability,Trie树
- poj1056 IMMEDIATE DECODABILITY (字典树)
- poj1056 http://poj.org/problem?id=1056
- poj1056 & hdu1305 & zoj1808 Immediate Decodability(字典树变形)
- QTE裁剪过程中各种参数的作用
- 限幅电路
- 什么是外部列表?
- 用java写星际争霸的ai
- c++内存管理学习纲要
- poj1056
- Python菜鸟初体验--纠结的工具选择
- Oracle数据库、表空间、用户创建
- WDF 驱动 pending 操作
- 20130607 近期遇到的SPI问题及分析
- 在Silverlight中嵌入HTML或aspx页面
- Windows编程-进程的创建
- 远程桌面的一些设置
- Vortex Library: BEEP Core implementation