#include <iostream> using namespace std; // write your code here...... void myswap(int *a,int *b){ int temp = *a; *a = *b; *b =temp; }//相当于交换了m和n的地址,自然修改了其中代表的值 //end int main() { int m, n; cin >> m; cin >> n; // write your code here...... myswap(&m,&n); //end cout << m << " " << n << endl; return 0; }
#include<stdio.h> void Exchange(int* m,int* n) { int temp = *m; *m = *n; *n = temp; } int main() { int m = 0; int n = 0; scanf("%d\n%d",&m,&n); Exchange(&m,&n); printf("%d %d",m,n); return 0; }
#include<stdio.h> int main() { int m,n; scanf("%d %d",&m,&n); int*p=&m; int*q=&n; int temp=0; temp=*p; *p=*q; *q=temp; printf("%d %d",m,n); return 0; }
#include <iostream> using namespace std; //交换都给玩烂掉了 // write your code here...... template <typename T> void myswap(T& a,T &b) { a ^= b; b ^= a; a ^= b; } // void myswap(int& a,int &b) // { // a += b; // b = a-b; // a = a-b; // } int main() { int m, n; cin >> m; cin >> n; // write your code here...... myswap<int>(m,n); cout << m << " " << n << endl; return 0; }
#include <iostream> using namespace std; // write your code here...... int main() { int m, n; cin >> m; cin >> n; // write your code here...... int *p1 = &m; int *p2 = &n; *p1 = *p1 - *p2; *p2 = *p1 + *p2; *p1 = *p2 - *p1; cout << m << " " << n << endl; return 0; }
#include <iostream> using namespace std; template <typename T> void Swap(T& a, T& b); template <typename T> void Swapp(T* a, T* b); int main() { int m, n; while(cin >> m >> n) { Swapp(&m, &n); //Swap(m, n); cout << m << " " << n << endl; } return 0; } template <typename T> void Swap(T& a, T& b) { T temp; temp = a; a = b; b = temp; } template <typename T> void Swapp(T* a, T* b) { T temp; temp = *a; *a = *b; *b = temp; }