Skip to content

Instantly share code, notes, and snippets.

@eliaperantoni
Created October 21, 2017 09:31
Show Gist options
  • Save eliaperantoni/787e3cfdcf9450b0f728b433f2ad5cf0 to your computer and use it in GitHub Desktop.
Save eliaperantoni/787e3cfdcf9450b0f728b433f2ad5cf0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define MAXN 20000
#define MAXM 20000
using namespace std;
enum PlugType{
L10, L16, BIP
};
class Server{
private:
PlugType plugType;
int power;
public:
PlugType getPlugType() const {return this -> plugType;}
int getPower() const {return this -> power;}
void setPlugType(PlugType plugType){if(plugType!=BIP)this -> plugType = plugType;}
void setPower(int power){this -> power = power;}
Server(PlugType plugType, int power){this -> plugType = plugType; this -> power = power;}
Server(){}
inline bool operator<(const Server& other) const {return getPower() < other.getPower();}
inline bool operator>(const Server& other) const {return getPower() > other.getPower();}
};
class Plug{
private:
PlugType plugType;
public:
PlugType getPlugType() const {return this -> plugType;}
void setPlugType(PlugType plugType){this -> plugType = plugType;}
Plug(PlugType plugType){this -> plugType = plugType;}
Plug(){}
};
int earn(int N, int M, int F[], char** T, char **S) {
vector<Server> servers;
vector<Plug> plugs;
// Preparo una lista di server
for(int i=0;i<N;i++){
Server server;
server.setPower(F[i]);
string serverPlugType(T[i]);
if(serverPlugType=="L10"){
server.setPlugType(L10);
}else{
server.setPlugType(L16);
}
servers.push_back(server);
}
sort(servers.begin(), servers.end());
// Preparo una lista di plug
for(int i=0;i<M;i++){
Plug plug;
string plugPlugType(S[i]);
if(plugPlugType=="L10"){
plug.setPlugType(L10);
}else if(plugPlugType=="L16"){
plug.setPlugType(L16);
}else{
plug.setPlugType(BIP);
}
plugs.push_back(plug);
}
return 42;
}
int F[MAXN];
char* T[MAXN];
char* S[MAXM];
int main() {
FILE *fr, *fw;
int N, M, i;
fr = fopen("input.txt", "r");
fw = fopen("output.txt", "w");
assert(2 == fscanf(fr, "%d%d", &N, &M));
for(i=0; i<N; i++)
assert(1 == fscanf(fr, "%d", &F[i]));
for(i=0; i<N; i++) {
T[i] = (char*) malloc(16 * sizeof(char*));
assert(1 == fscanf(fr, "%s", T[i]));
}
for(i=0; i<M; i++) {
S[i] = (char*) malloc(16 * sizeof(char*));
assert(1 == fscanf(fr, "%s", S[i]));
}
fprintf(fw, "%d\n", earn(N, M, F, T, S));
fclose(fr);
fclose(fw);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment