c_cpp 函数重载

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 函数重载相关的知识,希望对你有一定的参考价值。

#include <bits/stdc++.h>
using namespace std;

// Complete the sum function which gives the sum of all elements in a vector regardless of its dimensions
// Trying to use sum function without any input gives following output: "LoL F@$&#^"

int sum (vector< vector<int> >v){
    vector< vector<int> >a(v.size());
    int s = 0;
    for (int i=0; i<v.size();i++){
        for (int j=0; j<v[i].size(); j++){
            s += v[i][j];
        }
    }
    return s;
}

int sum (vector<int>v){
    vector<int>a(v.size());
    int s=0;
    for (int i=0; i<v.size(); i++){
        s += v[i];
    }
    return s;
}

string sum (){
    string s = "LoL F@$&#^";
    return s;
}

int main() {
	int t;
	cin>>t;
	while (t--){
	    int n;
	    cin>>n;
	    vector<int>a(n);
	    for(int i=0;i<n;i++){
	        cin>>a[i];
	    }
	    int r,c;
	    cin>>r>>c;
	    vector< vector<int> >b(r);
	    for (int i=0; i<r; i++){
	        b[i].resize(c);
	        for(int j=0;j<c;j++){
	            cin>>b[i][j];
	        }
	    }
	    cout<<sum(a)<<endl;
	    cout<<sum(b)<<endl;
	    cout<<sum()<<endl;
	    cout<<sum()<<endl;
	    cout<<sum()<<endl;
	    }
	return 0;
}



以上是关于c_cpp 函数重载的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp CPP - 教程008 - 递归算法和重载函数

c_cpp 运算符重载

c_cpp 重载和变换

c_cpp 重载调用运算符C ++

c_cpp 带有重载运算符的模板

c_cpp C ++中的运算符重载