栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【C++测试】MyCopy函数编写

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【C++测试】MyCopy函数编写

按要求补全函数模板。

#include 
#include 
using namespace std;

template 
struct MyCopy {
// 在此处补充你的代码
    void operator()(T *a, T *a_m, T *b) {
        T t[200];
        T *e=a;
        for(int i=0; a != a_m; i++)
        {
            t[i]=*a;
            a++;
        }
        a=e;
        for(int i=0; a != a_m; i++){
            *b = t[i];
            b++;
            a++;
        }
    }
};

int a[200];
int b[200];
string c[200];
string d[200];

template 
void Print(T s,T e) {
    for(; s != e; ++s)
        cout << * s << ",";
    cout << endl;
}

int main(){
    int m ;
    cin >> m;
    for(int i = 0;i < m; ++i)
        cin >> a[i];
    MyCopy()(a,a+m,b);
    Print(b,b+m);
    MyCopy()(a,a+m,a+m/2);
    Print(a+m/2,a+m/2 + m);
    for(int i = 0;i < m; ++i)
        cin >> c[i];
    MyCopy()(c,c+m,d);
    Print(c,c+m);
    MyCopy()(c,c+m,c+m/2);
    Print(c+m/2,c+m/2 + m);
    return 0;
}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/960026.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号