博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nullnull计算两个字符串链表中的共同数据项,需要考虑重复选项的情况
阅读量:7113 次
发布时间:2019-06-28

本文共 2036 字,大约阅读时间需要 6 分钟。

在写这篇文章之前,xxx已经写过了几篇关于改nullnull主题的文章,想要了解的朋友可以去翻一下之前的文章

    Problem

    每日一道理
谁说人与人隔着遥远的重洋,谁说心与心设着坚固的堤防?十六岁的鸟儿飞上天空,总会找到落脚的枝头。
/*
// Given two lists of strings build a new list that has all strings that appear in both the original lists. If the same string appears more than once output it as many times as it appears in both lists 
// 
// Example: 
// "dog", "bird", "elephant", "dog", "dog", "cat" 
// "cat", "dog", "dog", "cat", "cat", "fish" 
// Result (order doesn't matter) 
// "dog", "dog", "cat"
*/
Solution
#include 
#include
#include
#include
#include
using namespace std;void find_comm_strings(list
& output, list
& listA, list
& listB){ listA.sort(); listB.sort(); list
::const_iterator citA = listA.begin(); list
::const_iterator citB = listB.begin(); while(citA != listA.end() && citB != listB.end()){ int eq = (*citA).compare(*citB); if(eq == 0){ output.push_back(*citA); citA ++; citB ++; } else if (eq > 0){ citB ++; } else{ citA ++; } }}int main(int argc, char* argv[]){ list
listA; list
listB; list
output; cout << "list A:" << endl; listA.push_back("dog"); listA.push_back("bird"); listA.push_back("elephant"); listA.push_back("dog"); listA.push_back("dog"); listA.push_back("cat"); copy(listA.begin(), listA.end(), ostream_iterator
(cout, ",")); cout << endl; cout << "list B:" << endl; listB.push_back("cat"); listB.push_back("dog"); listB.push_back("dog"); listB.push_back("cat"); listB.push_back("cat"); listB.push_back("fish"); copy(listB.begin(), listB.end(), ostream_iterator
(cout, ",")); cout << endl; find_comm_strings(output, listA, listB); cout << "common strings" << endl; copy(output.begin(), output.end(), ostream_iterator
(cout, ",")); cout << endl; return 0;}
Output
list A:dog,bird,elephant,dog,dog,cat,list B:cat,dog,dog,cat,cat,fish,common stringscat,dog,dog,Press any key to continue . . .

文章结束给大家分享下程序员的一些笑话语录: 问:你觉得让你女朋友(或者任何一个女的)从你和李彦宏之间选一个,你觉得她会选谁?  

  答:因为李艳红这种败类,所以我没女友!

转载地址:http://sughl.baihongyu.com/

你可能感兴趣的文章
Android 控件在布局中按比例放置[转]
查看>>
内核通知链 学习笔记 【转】
查看>>
Input Method of Win32 System
查看>>
count(*) VS count(X)
查看>>
MS ASP.Net Ajax 服务端扩展
查看>>
android102 查询,插入联系人
查看>>
数据库邮件
查看>>
adstrtal.sh报超时错误 ERROR : Timed out( 100000 ): Interrupted Exception
查看>>
一个前端工程师的基本修养
查看>>
ZT:三十个好习惯
查看>>
.Net开发笔记(七)使用组件编程
查看>>
ASP.NET企业开发框架IsLine FrameWork系列之八--AppLogProvider日志框架(下)
查看>>
DataBase异常状态:Recovery Pending,Suspect,估计Recovery的剩余时间
查看>>
一个android版本的rss阅读器--明天补充实现过程,先上图
查看>>
WPF TreeView
查看>>
HTML: 仿写一个财经类静态的网页
查看>>
C#读写config配置文件
查看>>
JavaScript:文本域事件处理
查看>>
关于dctser进程
查看>>
一步一步教你使用AgileEAS.NET基础类库进行应用开发-基础篇-演示ORM中的查询
查看>>