Pages

Tuesday, June 5, 2012

10258 - Contest Scoreboard

Remember, there is penalty of only '20' when it is Incorrect (I), and the penalty for a particular problem for a particular contentment is considered only if he/she submits the correct solution for it, and after that no penalty is accounted for that particular problem for that contestant.

and you can do better by making a better comparison function.


//
// main.cpp
// 10258 - Contest Scoreboard
//
// Created by Panks on 31/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cstdio>
using namespace std;

struct info {
int id;
int problems[12];
int penalty[12];
int tsolved;
int time;
};

bool cmp(info a, info b);
bool cmp(info a, info b){
if (a.tsolved<b.tsolved) {
return false;
}else if(a.tsolved>b.tsolved){
return true;
}else{
if (a.penalty[11]<b.penalty[11]) {
return true;
}else if(a.penalty[11]>b.penalty[11]){
return false;
}else{
return (a.id-b.id)<0;
}
}

}


int main (int argc, const char * argv[])
{
vector<info> store;
int t,contestant,problem,time;
string L;
string input;
stringstream ss;
cin>>t;
getchar();
info data;
data.id=0; fill_n(data.problems,12, 0);
fill_n(data.penalty,12, 0); data.time=0, data.tsolved=0;;
getchar();
while (t--) {
getline(cin,input);
store.resize(101);
fill_n(store.begin(), 101, data);

while (input!="") {
ss.str(input);
ss>>contestant; ss>>problem; ss>>time; ss>>L;
if (!L.compare("C")) {
store[contestant].id=contestant;
if (store[contestant].problems[problem]==0) {
store[contestant].problems[problem]=1;
store[contestant].penalty[problem]+=time;
}
}else if (!L.compare("I")) {
store[contestant].id=contestant;
if (store[contestant].problems[problem]==0) {
store[contestant].penalty[problem]+=20;
}
}else{
store[contestant].id=contestant;
}
getline(cin, input);
ss.clear();
}

for (int i=0; i<store.size(); i++) {
for (int j=0; j<10; j++) {
if (store[i].problems[j]) {
store[i].tsolved++;
store[i].penalty[11]+=store[i].penalty[j];
}
}

}

sort(store.begin(), store.end(), cmp);
for (int i=0; i<store.size(); i++) {
if (store[i].id==0) {
continue;
}
cout<<store[i].id<<" "<<store[i].tsolved<<" "<<store[i].penalty[11]<<endl;
}

if (t!=0) {
cout<<endl;
}
store.clear();
ss.clear();

}
return 0;
}

Sunday, June 3, 2012

482 - Permutation Arrays


//
// main.cpp
// 482 - Permutation Arrays
//
// Created by Panks on 30/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (int argc, const char * argv[])
{
int t, count=0;
string line1, line2;
int index;
string value;
vector<pair<int, string> > store;
cin>>t;
getchar();
while (t--) {
getchar();
count++;
getline(cin, line1);
getline(cin, line2);
stringstream ss1(line1), ss2(line2);
while (ss1>>index) {
ss2>>value;
store.push_back(pair<int, string>(index, value));
}
sort(store.begin(), store.end());
if (count>1) {
cout<<endl;
}
for (int i=0; i<store.size(); i++) {
cout<<store[i].second<<endl;
}

store.clear();
}
return 0;
}

Saturday, June 2, 2012

11498 - Division of Nlogonia



// main.cpp
// 11498 - Division of Nlogonia
//
// Created by Panks on 29/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int k,n,m;
int x,y;
cin>>k;
while (k!=0) {
cin>>n>>m;
while (k--) {
cin>>x>>y;
if (x==n||y==m) {
cout<<"divisa\n";
continue;
}else{
if (x<n) {
if (y<m) {
cout<<"SO\n";
}else{
cout<<"NO\n";
}

}else{

if (y<m) {
cout<<"SE\n";
}else{
cout<<"NE\n";
}

}
}
}
cin>>k;
}

return 0;
}


11340 - Newspaper


//
// main.cpp
// 11340 - Newspaper
//
// Created by Panks on 31/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int main (int argc, const char * argv[])
{

int t,in;
double answer;
char letter;
int vals;
string line;
map<char, int> values;

cin>>t;
while (t--) {

answer=0;
cin>>in;
while (in--) {
cin>>letter>>vals;
values.insert(pair<char, int>(letter, vals));
}
cin>>in;
getchar();
while (in--) {
getline(cin, line);
for (int i=0; i<line.size() ; i++) {
if (values[line[i]]) {
answer+=values[line[i]];
}
}
}
answer/=100;
printf("%.2f$\n", answer);

values.clear();

}
return 0;
}


11150 - Cola

Just scribe a little on paper, you would get it. ;)

//
// main.cpp
// 11150 - Cola
//
// Created by Panks on 29/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

int a, tmp;
while (cin>>a) {
if (a==1||a==0) {
cout<<a<<endl;
continue;
}
tmp=a;
a=a+a/2;
a=a-a%3;
cout<<tmp+(a/3)<<endl;
}
return 0;
}

11044 - Searching for Nessy


//
// main.cpp
// 11044 - Searching for Nessy
//
// Created by Panks on 29/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

int t;
double a,b, froma, fromb;
int ifroma, ifromb;
cin>>t;
while (t--) {
cin>>a>>b;
a-=2;
b-=2;
froma=a/3.0;
fromb=b/3.0;

if (froma-(int)froma!=0) {
ifroma=(int)froma+1;
}else{
ifroma=(int)froma;
}


if (fromb-(int)fromb!=0) {
ifromb=(int)fromb+1;
}else{
ifromb=(int)fromb;
}

cout<<ifroma*ifromb<<endl;
}
return 0;
}

10921 - Find the Telephone


//
// main.cpp
// 10921 - Find the Telephone
//
// Created by Panks on 28/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <algorithm>
using namespace std;


void doit(char a);
string *str=new string[8];
using namespace std;
int main (int argc, const char * argv[])
{

str[0]="ABC", str[1]="DEF", str[2]="GHI", str[3]="JKL", str[4]="MNO", str[5]="PQRS", str[6]="TUV", str[7]="WXYZ";
string input;
while (getline(cin, input)){
for_each(input.begin(), input.end(), doit);
cout<<endl;
}
return 0;
}


void doit(char a){
bool done=false;
for (int i=0; i<8; i++) {
if (count(str[i].begin(), str[i].end(), a)) {
cout<<i+2;
done=true;
}
}

if (!done) {
cout<<a;
}
}