TopCoder

User's AC Ratio

100.0% (1/1)

Submission's AC Ratio

50.0% (1/2)

Tags

Description

template練習

● 給大家的話

請乖乖使用template解題,不要用其他方法通過,大家自由心證 ><

● 題目敘述

實作一個 \(swap\) 函式,支援以下型態 \(:\)

  • \(int\)
  • \(double\)
  • \(long\) \(long\) \(int\)

● 補充

test 1:只有int

test 2:只有double

test 3:只有long long int

test 4:範測1

test 5:範測2

test 6:其他測資

● 簡單的模板

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;


template<class T>
void swap(/*......*/){
    /* implement swap function */



}

int main()
{
    // str 可能是 int,long long int,double
    char str[20];
    cin >> str;

    // array 有 N 個整數
    // 對 array 做 M 組操作
    int N,M;
    cin >> N >> M;

    if(!strcmp(str,"int")){
        /* do something */
    
    }
    else if(!strcmp(str,"longlongint")){
        /* do something */

    }
    else if(!strcmp(str,"double")){
        /* do something */

    }
    cout << endl;
}

Input Format

第 \(1\) 行,輸入字串 \(str\),表示數字的型態。

第 \(2\) 行,輸入 \(2\) 個整數 \(N\) 、 \(M\) ,表示有 \(N\) 個數字和 \(M\) 組 \(swap\)操作

第 \(3\) 行,輸入 \(N\) 個數字

剩下的 \(M\) 行,每行輸入兩個整數 \(i、j\),代表要 \(swap\) 的數字索引值 \(index\)

\(e.g.,\) 輸入 \(1\)、\(5\),表示第 \(1\) 個數字和第 \(5\) 個數字 \(swap\)

  • \(1 \leq N \leq 10^2\)
  • \(1 \leq M \leq 10^5\)
  • \(0 \leq i、j \leq N-1\)

Output Format

輸出全部數字,並換行

Sample Input 1

5 2
1 2 3 4 5
0 4
1 2

Sample Output 1

5 3 2 4 1

Sample Input 2

5 2
1.1 2.2 3.3 4.4 5.5
0 4
1 2

Sample Output 2

5.5 3.3 2.2 4.4 1.1

Sample Input 3

5 2
10000016205 10000026249 10000021834 10000010522 10000009507
3 1
4 1

Sample Output 3

10000016205 10000009507 10000021834 10000026249 10000010522

Hints

Problem Source

NEOJ Problem 595

Subtasks

No. Testdata Range Constraints Score
1 0~9 10
2 10~19 10
3 20~29 10
4 30 10
5 31 10
6 32 10

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 65536 1
1 1000 65536 65536 1
2 1000 65536 65536 1
3 1000 65536 65536 1
4 1000 65536 65536 1
5 1000 65536 65536 1
6 1000 65536 65536 1
7 1000 65536 65536 1
8 1000 65536 65536 1
9 1000 65536 65536 1
10 1000 65536 65536 2
11 1000 65536 65536 2
12 1000 65536 65536 2
13 1000 65536 65536 2
14 1000 65536 65536 2
15 1000 65536 65536 2
16 1000 65536 65536 2
17 1000 65536 65536 2
18 1000 65536 65536 2
19 1000 65536 65536 2
20 1000 65536 65536 3
21 1000 65536 65536 3
22 1000 65536 65536 3
23 1000 65536 65536 3
24 1000 65536 65536 3
25 1000 65536 65536 3
26 1000 65536 65536 3
27 1000 65536 65536 3
28 1000 65536 65536 3
29 1000 65536 65536 3
30 1000 65536 65536 4
31 1000 65536 65536 5
32 1000 65536 65536 6