8402: STL 函数使用 —— swap()
[Creator : ]
Description
【介绍】
【头文件】
Standard Template Library: Algorithms#include<utility>
【作用】
Exchange values of two obExchanges the values of a and b.
header // moved from <algorithm> to <utility> in C++11 non-array (1) template <class T> void swap (T& a, T& b) noexcept (is_nothrow_move_constructible<T>::value && is_nothrow_move_assignable<T>::value); array (2) template <class T, size_t N> void swap(T (&a)[N], T (&b)[N]) noexcept (noexcept(swap(*a,*b)));
注意:
$a,b$ 必须是相同的数据类型即可。任何数据类型都可以,只要是相同类型。
如果 $a,b$ 的数据类型不同,比如 int a; long long b; 都会导致编译错误。
【任务】
下面,我们使用 swap() 函数,完成交换 $a,b$ 的数值。Input
一行包括两个整数 $a,b\ (-10^9 \leq a,b \leq 10^9)$,整数之间用空格隔开。
Output
一行包括两个整数,表示将整数 $a,b$ 交换后结果。
Sample 1 Input
1 2
Sample 1 Output
2 1
Sample 2 Input
1034 -15349
Sample 2 Output
-15349 1034