C++面向对象程序设计 028:简单的foreach ---- (北大Mooc)
发布日期:2021-06-30 22:27:46
浏览次数:2
分类:技术文章
本文共 660 字,大约阅读时间需要 2 分钟。
文章目录
专题博客链接
原题题目
#include#include using namespace std;// 在此处补充你的代码void Print(string s){ cout << s;}void Inc(int & n){ ++ n;}string array[100];int a[100];int main() { int m,n; while(cin >> m >> n) { for(int i = 0;i < m; ++i) cin >> array[i]; for(int j = 0; j < n; ++j) cin >> a[j]; MyForeach(array,array+m,Print); cout << endl; MyForeach(a,a+n,Inc); for(int i = 0;i < n; ++i) cout << a[i] << ","; cout << endl; } return 0;}
代码实现
templatevoid MyForeach(T1* startptr,T1* endptr,T2* tempprint){ T1* temp; for(temp = startptr;temp != endptr;temp++) (*tempprint)(*temp); return;}
转载地址:https://love6.blog.csdn.net/article/details/114991278 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月30日 07时27分40秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
CodeForces - 456C Boredom (dp)
2019-04-30
CodeForces - 960B Minimize the error (思维,贪心)
2019-04-30
CodeForces - 97B Superset (思维/分治/构造)
2019-04-30
CodeForces - 675A Infinite Sequence(简单数论 细节)
2019-04-30
CodeForces - 1042B Vitamins (思维)
2019-04-30
ACM 2013 长沙区域赛 Collision (几何)
2019-04-30
ACM 2014 鞍山区域赛 E - Hatsune Miku (dp)
2019-04-30
反向传播&梯度下降 的直观理解程序(numpy)
2019-04-30
CodeForces - 931B World Cup (思维 模拟)
2019-04-30
ACM 2017 北京区域赛 J-Pangu and Stones(区间dp)
2019-04-30
HDU - 5643 King's Game (约瑟夫环变式)
2019-04-30
UVA - 1452 Jump (约瑟夫环变式)
2019-04-30
POJ - 3517 And Then There Was One (约瑟夫环变式)
2019-04-30
HDU - 2068 RPG的错排 (错排+组合数)
2019-04-30
CodeForces 591C Median Smoothing(思维 模拟)
2019-04-30
升级yosemite后java出错的解决
2019-04-30
mac || Linux 命令行下实现批量重命名
2019-04-30
java常用类 String面试题
2019-04-30