华为OJ中级题-查找兄弟单词
2015-12-08 08:59
357 查看
bool findBrother(string x,string y){ int len = x.length(); if (len != y.length()){ return false; } if (x == y){ return false; } int book[256] = { 0 }, book2[256] = {0}; for (int i = 0; i < len; ++i){ ++book[x[i]]; } int c = 0; for (int i = 0; i < len; ++i){ for (int j = 0; j < len; ++j){ if (x[i] == y[j]&&book2[y[j]]<book[x[j]]){ ++c; ++book2[y[j]]; } } } if (c == len)return true; else return false; } void HWoj(){ int N,n; vector<string> words,outStr; string tmp; cin >> N; while (N--){ cin >> tmp; words.push_back(tmp); } cin >> tmp; cin >> n; int lens = words.size(); int count=0; int i = 0; for (i; i < lens; ++i){ if (findBrother(tmp, words.at(i))){ ++count; outStr.push_back(words.at(i)); } } lens = outStr.size(); cout << count << endl; sort(outStr.begin(), outStr.end()); cout << outStr.at(n-1) << endl; }
相关文章推荐
- Genymotion不能启动,提示”VirtualBox cannot start virtual device“如何处理
- sql where 1=1 0=1 的妙用
- 面向对象 对象属性 例
- hadoop2.6上部署spark
- 关于成本中心计划与过账
- 轻松学习JavaScript十二:JavaScript基于面向对象之创建对象(一)
- ubuntu下使用sublime text时如何完美输入中文
- iOS 【cartool的使用】
- Kafka学习7_使用log.retention.hours改变消息端的消息保存时间
- Eclipse注释模板
- hdu5556 2015ACM合肥现场赛题 二分图最大独立集
- 点击事件的参数问题
- DM9000网卡驱动源码分析系列03 - probe && remove
- 17.1 简单文本输出
- Linux之旅——Linux简介
- MySQL复合分区
- 详解Java的Spring框架下bean的自动装载方式
- http://www.cnblogs.com/xwdreamer/archive/2012/02/21/2360818.html
- 保留四位有效小数
- 手机充电(练习)