## 12004 - Bubble Sort

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### 12004 - Bubble Sort

Input:

Code: Select all

``````5
103
992
1042
555
1234``````
AC output:

Code: Select all

``````Case 1: 5253/2
Case 2: 245768
Case 3: 542361/2
Case 4: 153735/2
Case 5: 760761/2``````
Check input and AC output for thousands of problems on uDebug!

dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

### Re: 12004 - Bubble Sort

Input:

Code: Select all

``````10
10000
20000
30000
40000
50000
60000
70000
80000
90000
100000``````
Output:

Code: Select all

``````Case 1: 24997500
Case 2: 99995000
Case 3: 224992500
Case 4: 399990000
Case 5: 624987500
Case 6: 899985000
Case 7: 1224982500
Case 8: 1599980000
Case 9: 2024977500
Case 10: 2499975000``````
[/size]
Life shouldn't be null.

New poster
Posts: 16
Joined: Thu Oct 10, 2013 8:06 am

### Re: 12004 - Bubble Sort

Code: Select all

``````#include <iostream>
#include <cstdio>

using namespace std;

long long int num;
int main()
{
long long int test;
cin >> test;
for(int i=1;i<=test;i++)
{
cin >> num;
if(num%4==0)
{
num=(num*(num-1))/4;
cout << "Case "<< i <<": "<<num << endl;
}
else
{
num=(num*(num-1))/2;
cout << "Case "<< i <<": "<< num << "/" << "2"<<endl;
}
}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 12004 - Bubble Sort

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 12004 - Bubble Sort

Code: Select all

``````a = 1 2 3 4, findSwaps = 0
a = 1 2 4 3, findSwaps = 1
a = 1 3 2 4, findSwaps = 1
a = 1 3 4 2, findSwaps = 2
a = 1 4 2 3, findSwaps = 2
a = 1 4 3 2, findSwaps = 3
a = 2 1 3 4, findSwaps = 1
a = 2 1 4 3, findSwaps = 2
a = 2 3 1 4, findSwaps = 2
a = 2 3 4 1, findSwaps = 3
a = 2 4 1 3, findSwaps = 3
a = 2 4 3 1, findSwaps = 4
a = 3 1 2 4, findSwaps = 2
a = 3 1 4 2, findSwaps = 3
a = 3 2 1 4, findSwaps = 3
a = 3 2 4 1, findSwaps = 4
a = 3 4 1 2, findSwaps = 4
a = 3 4 2 1, findSwaps = 5
a = 4 1 2 3, findSwaps = 3
a = 4 1 3 2, findSwaps = 4
a = 4 2 1 3, findSwaps = 4
a = 4 2 3 1, findSwaps = 5
a = 4 3 1 2, findSwaps = 5
a = 4 3 2 1, findSwaps = 6
n = 4, total Swaps = 72, permutations = 24
``````
Check input and AC output for thousands of problems on uDebug!