C++ 面向对象程序设计上机练习四(变量引用)

来源:互联网 发布:985贴吧 知乎 编辑:程序博客网 时间:2024/05/22 05:29

题目链接:点击打开链接

面向对象程序设计上机练习四(变量引用)

Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic

Problem Description

将变量的引用作为函数形参,实现2个int型数据交换。

Input

输入2个int型整数。

Output

输出2个整数交换前后的值。

Example Input

88 66

Example Output

88 6666 88

Hint

Author

zlh 

代码实现:

#include <iostream>using namespace std;template <typename T>T Swap(T &a,T &b){    T c = a;    a = b;    b = c;}int main(){    int a,b;    cin>>a>>b;    cout<<a<<" "<<b<<endl;    Swap(a,b);    cout<<a<<" "<<b<<endl;    return 0;}


0 0
原创粉丝点击