Skip to content

Commit

Permalink
3 codechef problems (gopalgoel19#24)
Browse files Browse the repository at this point in the history
* Codechef October Challenge 17 perfcont.cpp

* Added 3 more problems in codechef

* Delete perfcont.cpp
  • Loading branch information
adikul30 authored and gopalgoel19 committed Oct 11, 2017
1 parent 4cd25a4 commit d203c10
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
56 changes: 56 additions & 0 deletions codechef/cleanup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <bits/stdc++.h>

using namespace std;

#define INF (int)1e9
#define EPS 1e-9
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define PB push_back
#define MP make_pair

typedef long long ll;
typedef pair<int, int> PII;
// vector<int> VI,chef,chefas;
typedef vector<string> VS;
typedef vector<PII> VII;

const float PI = 3.1415926535897932384626433832795;
const int MOD = 1000000007;

int main()
{
int t,i,j,n,m,temp;

scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
vector<int> VI,chef,chefas;
for (i = 1; i <= n; i++) VI.push_back(i);

for (i = 1; i <= m; i++){
scanf("%d",&temp);
VI.erase(std::remove(VI.begin(), VI.end(), temp), VI.end());
}

sort(VI.begin(),VI.end());

for(i=0; i < VI.size(); i++){
if (i%2==0){
chef.push_back(VI[i]);
}
else {
chefas.push_back(VI[i]);
}
}
for (i = 0; i < chef.size(); i++){
printf("%d ",chef[i]);
}
printf("\n");
for (i = 0; i < chefas.size(); i++){
printf("%d ",chefas[i]);
}
printf("\n");
}

return 0;
}
42 changes: 42 additions & 0 deletions codechef/horses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>

using namespace std;

#define INF (int)1e9
#define EPS 1e-9
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define PB push_back
#define MP make_pair

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;

const float PI = 3.1415926535897932384626433832795;
const int MOD = 1000000007;

int main()
{
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int arr[n];
for (int i = 0; i < n; i++)
scanf("%d",&arr[i]);
sort(arr,arr+n);

int min = arr[1] - arr[0];

for (int i = 0; i < n-1; ++i){
int temp = arr[i+1] - arr[i];
if (temp<min){
min = temp;
}
}
printf("%d\n",min);
}
return 0;
}
25 changes: 25 additions & 0 deletions codechef/johny.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; ++i)

int main()
{
int t,n,i,j,k,val;
cin >> t;
while(t--){
cin >> n;
int arr[n+1];
REP(i,1,n+1)scanf("%d",&arr[i]);
scanf("%d",&k);
val = arr[k];
sort(arr+1,arr+n+1);
REP(i,1,n+1)
if (val == arr[i]){
cout << i << endl;
break;
}
}
return 0;
}

0 comments on commit d203c10

Please sign in to comment.