POJ 1016: Numbers That Count
2016-01-25 11:04
369 查看
没啥说的.
代码如下:
代码如下:
#include <iostream> #include <vector> using namespace std; void kronecker( vector<string>& v, int cnt ) { vector<int> cal( 10, 0 ); for( string::const_iterator pos = v[cnt].begin(); pos < v[cnt].end(); ++pos ) { ++cal[*pos - '0']; } v[++cnt].clear(); for( int i = 0; i < 10; ++i ) { if( cal[i] != 0 ) { if( cal[i] >= 10 ) { v[cnt] += char( cal[i] / 10 + '0' ); } v[cnt] += char( cal[i] % 10 + '0' ); v[cnt] += char( i + '0' ); } } if( v[cnt] == v[cnt - 1] ) { if( cnt == 1 ) { cout << v[0] << " is self-inventorying" << endl; } else { cout << v[0] << " is self-inventorying after " << cnt - 1 << " steps" << endl; } return; } for( int i = 0; i < cnt; ++i ) { if( v[cnt] == v[i] ) { cout << v[0] << " enters an inventory loop of length " << cnt - i << endl; return; } } if( cnt == 15 ) { cout << v[0] << " can not be classified after 15 iterations" << endl; return; } kronecker( v, cnt ); } int main() { vector<string> v( 16 ); while( cin >> v[0] && v[0][0] != '-' ) { kronecker( v, 0 ); } }
相关文章推荐
- android 网络变化流程
- java中文乱码解决之道(三)-----编码详情:伟大的创想---Unicode编码
- Linux C include路径问题
- assign与weak的区别?
- 网页增重不可控?试试 OneAPM Cloud Test
- MySQL 修改字段类型或长度
- SQL Server中的窗口计算
- jquery根据name取得select选中的值
- MindMapper中如何添加父主题
- in-band network management and out-of-band management
- spring的事物管理配置
- 初识cordova插件开发
- iOS开发系列--通知与消息机制
- linux增加swap空间
- java中文乱码解决之道(二)-----字符编码详解:基础知识 + ASCII + GB**
- poj1328 Radar Installation 贪心 (手动翻译)
- TCP closing a connection
- 利用wireshark抓取远程linux上的数据包
- 通过sqlserver 2008 r2传输cmd命令
- Angular JS select 下拉框设置value