MPGHCC Results
http://www.mpgh.net/forum/31-c-c/131...g-contest.html
Congratualtions for Seamone for winning with 150 points!
Here are the answers:
Problems 1 :
Problem 2: DoS Attack!
Problem 3: Trojan Firewall
Problem 4: Server
Problem 5: Shortest path
Don't feel like doing it right now but its BFS / DFS.
The next contest will start this Saturday and will end the next Sunday. I will be changing the format of the contest and will try to be more specific on each question. If you have any questions/comments/suggestions feel free to reply to this post, PM me or email me.
Congratualtions for Seamone for winning with 150 points!
Here are the answers:
Problems 1 :
Code:
#include <iostream>
using namespace std;
int main(void){
freopen("count.txt","r",stdin);
int t;
for(i=0;i<5;i++){
int n;
int leecher=0,coder=0;
cin>>n;
for(i=0;i<n;i++){
int postcount;
int rep;
cin>>postcount;
cin>>rep;
if(postcount*rep>=500)coder++;
else leecher++;
}
printf("There are %d Coder(s) and %d Leecher(s).\n",coder,leecher);
}
}
Code:
#include <iostream>
using namespace std;
int main(void){
freopen("dosattack.txt","r",stdin);
int t;
for(t=0;t<5;t++){
int i;
int n;
int filter;
cin>>n;
cin>>filter;
int id=0,connect=0;
int arr[100];
for(i=0;i<n;i++){
cin>>arr[i];
}
for(i=0;i<n;i++){
int te***ount=0;
while(arr[i+1]==arr[i]){
i++;
te***ount++;}
te***ount++;
if(te***ount>filter){
id = arr[i];
connect=te***ount;
}
}
if(connect)printf("DoS Alert! Connection ID of %d of the same %d connections.",id,connect);
else cout<<"No DoS detected!";
cout<<endl;
}
}
Code:
#include <iostream>
using namespace std;
int main(void){
//freopen("trojan.txt","r",stdin);
int t;
for(t=0;t<5;t++){
char str[100];
cin>>str;
int sum=0;
int group;
int i;
if(strlen(str)%4==0)group=strlen(str)/4;
else group=(strlen(str)/4)+1;
for(i=0;i<strlen(str);i+=4){
sum+=str[i]-'A'+1;
}
if(sum%group==0)printf("Trojan with code %d!",sum/group);
else cout<<"Not a trojan!";
cout<<endl;
}
}
Code:
#include <iostream>
using namespace std;
int compare (const void * a,const void * b){
return ( *(int*)a - *(int*)b);
} //courtesy of cpluscplus reference
int main(void){
freopen("server.txt","r",stdin);
int t;
for(t=0;t<5;t++){
int n;
int arr[100];
cin>>n;
int i;
for(i=0;i<n;i++)cin>>arr[i];
qsort(arr,n,sizeof(int),compare);
if(n%2==1)printf("Server will be located at %d.",arr[n/2]);
else printf("Server will be located at %f.",(float)(arr[n/2]+arr[(n/2)-1])/2);
cout<<endl;
}
}
Don't feel like doing it right now but its BFS / DFS.
The next contest will start this Saturday and will end the next Sunday. I will be changing the format of the contest and will try to be more specific on each question. If you have any questions/comments/suggestions feel free to reply to this post, PM me or email me.
(or if you want me to look your post over to see whether or not someone else would think it's confusing etc feel free to PM me, I'd be glad to help out)
