其他分享
首页 > 其他分享> > 28

28

作者:互联网

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 template<class T,class Pred>
 5 void MyForeach(T *p,T *q,Pred op){
 6     while(p != q){
 7         op(*p);
 8         ++ p;
 9     }
10 }
11 void Print(string s)
12 {
13     cout << s;
14 }
15 void Inc(int & n)
16 {
17     ++ n;
18 }
19 string array[100];
20 int a[100];
21 int main() {
22     int m,n;
23     while(cin >> m >> n) {
24         for(int i = 0;i < m; ++i)
25             cin >> array[i];
26         for(int j = 0; j < n; ++j)
27             cin >> a[j];
28         MyForeach(array,array+m,Print);         
29         cout << endl;
30         MyForeach(a,a+n,Inc);         
31         for(int i = 0;i < n; ++i)
32             cout << a[i] << ",";
33         cout << endl;
34     }
35     return 0;
36 }

 

标签:MyForeach,++,28,int,Print,array
来源: https://www.cnblogs.com/balabalabubalabala/p/16691287.html