SELF DESCRIBING NUMBERS题解
来源:互联网 发布:k线绘图软件 编辑:程序博客网 时间:2024/05/16 16:53
这一题要采用逆向思维,不要去判断每个数字出现的有没有这么多,而是去统计数字出现的次数,反过来构造出对应的描述数字,如果描述数字跟原来的数字相等,那就是self described的数
#include <iostream>#include <fstream>#include <string>using namespace std;string self_describe(string lineBuffer) {string res = "";size_t size = lineBuffer.size();int b[10] = {0};for(size_t i=0; i<size; i++) {++b[lineBuffer[i]-'0'];}for(size_t i=0; i<size; i++) {res += (b[i]+'0');}return res;}int main (int argc, char* argv[]) {ifstream file;string lineBuffer;file.open(argv[1]);while (!file.eof()) {getline(file, lineBuffer);if (lineBuffer.length() == 0)continue; //ignore all empty lineselse {if(lineBuffer == self_describe(lineBuffer)) cout << "1\n";elsecout << "0\n";}}return 0;}
0 0
- SELF DESCRIBING NUMBERS题解
- Self Describing Numbers自描述数字问题(Python版)
- Self-describing Sequence ACM
- uva 10049 self describing sequence
- UVa Problem Solution: 10049 - Self-describing Sequence
- Self Numbers
- Self Numbers
- Self Numbers
- Self Numbers
- UVa Problem 10049 Self-describing Sequence (自描述序列)
- zoj1180 Self Numbers
- POJ 1316 Self Numbers
- fjnu 1884 Self Numbers
- ACM题-Self Numbers
- pku 1316 Self Numbers
- zoj 1180 Self Numbers
- POJ 1316 Self Numbers
- hdu 1128 Self Numbers
- Remove Duplicates from Sorted List
- mysql存储空间使用观察
- 各种排序算法的实现-8(选择排序的实现)
- HBase 健康检查工具
- ORA-01003: no statement parsed
- SELF DESCRIBING NUMBERS题解
- SWAP CASE题解
- 在flex技术中使用flash导出的swc中的flash元件的方法
- const参数,const返回值与const函数
- 软件项目开发管理过程中值得借助的一些工具
- 墨香游戏服务器架构
- 初学Java多线程:线程简介
- flex组件的生命周期
- DP28 求能变成回文的最小插入字符个数 Minimum insertions to form a palindrome @geeksforgeeks