June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
119
Task/Ranking-methods/C/ranking-methods.c
Normal file
119
Task/Ranking-methods/C/ranking-methods.c
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*Abhishek Ghosh, 5th November 2017*/
|
||||
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
|
||||
typedef struct{
|
||||
int score;
|
||||
char name[100];
|
||||
}entry;
|
||||
|
||||
void ordinalRanking(entry* list,int len){
|
||||
|
||||
int i;
|
||||
|
||||
printf("\n\nOrdinal Ranking\n---------------");
|
||||
|
||||
for(i=0;i<len;i++)
|
||||
printf("\n%d\t%d\t%s",i+1,list[i].score,list[i].name);
|
||||
}
|
||||
|
||||
void standardRanking(entry* list,int len){
|
||||
|
||||
int i,j=1;
|
||||
|
||||
printf("\n\nStandard Ranking\n----------------");
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
printf("\n%d\t%d\t%s",j,list[i].score,list[i].name);
|
||||
if(list[i+1].score<list[i].score)
|
||||
j = i+2;
|
||||
}
|
||||
}
|
||||
|
||||
void denseRanking(entry* list,int len){
|
||||
|
||||
int i,j=1;
|
||||
|
||||
printf("\n\nDense Ranking\n-------------");
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
printf("\n%d\t%d\t%s",j,list[i].score,list[i].name);
|
||||
if(list[i+1].score<list[i].score)
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
void modifiedRanking(entry* list,int len){
|
||||
|
||||
int i,j,count;
|
||||
|
||||
printf("\n\nModified Ranking\n----------------");
|
||||
|
||||
for(i=0;i<len-1;i++){
|
||||
if(list[i].score!=list[i+1].score){
|
||||
printf("\n%d\t%d\t%s",i+1,list[i].score,list[i].name);
|
||||
count = 1;
|
||||
for(j=i+1;list[j].score==list[j+1].score && j<len-1;j++)
|
||||
count ++;
|
||||
for(j=0;j<count-1;j++)
|
||||
printf("\n%d\t%d\t%s",i+count+1,list[i+j+1].score,list[i+j+1].name);
|
||||
i += (count-1);
|
||||
}
|
||||
}
|
||||
printf("\n%d\t%d\t%s",len,list[len-1].score,list[len-1].name);
|
||||
}
|
||||
|
||||
void fractionalRanking(entry* list,int len){
|
||||
|
||||
int i,j,count;
|
||||
float sum = 0;
|
||||
|
||||
printf("\n\nFractional Ranking\n------------------");
|
||||
|
||||
for(i=0;i<len;i++){
|
||||
if(i==len-1 || list[i].score!=list[i+1].score)
|
||||
printf("\n%.1f\t%d\t%s",(float)(i+1),list[i].score,list[i].name);
|
||||
else if(list[i].score==list[i+1].score){
|
||||
sum = i;
|
||||
count = 1;
|
||||
for(j=i;list[j].score==list[j+1].score;j++){
|
||||
sum += (j+1);
|
||||
count ++;
|
||||
}
|
||||
for(j=0;j<count;j++)
|
||||
printf("\n%.1f\t%d\t%s",sum/count + 1,list[i+j].score,list[i+j].name);
|
||||
i += (count-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void processFile(char* fileName){
|
||||
FILE* fp = fopen(fileName,"r");
|
||||
entry* list;
|
||||
int i,num;
|
||||
|
||||
fscanf(fp,"%d",&num);
|
||||
|
||||
list = (entry*)malloc(num*sizeof(entry));
|
||||
|
||||
for(i=0;i<num;i++)
|
||||
fscanf(fp,"%d%s",&list[i].score,list[i].name);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
ordinalRanking(list,num);
|
||||
standardRanking(list,num);
|
||||
denseRanking(list,num);
|
||||
modifiedRanking(list,num);
|
||||
fractionalRanking(list,num);
|
||||
}
|
||||
|
||||
int main(int argC,char* argV[])
|
||||
{
|
||||
if(argC!=2)
|
||||
printf("Usage %s <score list file>");
|
||||
else
|
||||
processFile(argV[1]);
|
||||
return 0;
|
||||
}
|
||||
167
Task/Ranking-methods/D/ranking-methods.d
Normal file
167
Task/Ranking-methods/D/ranking-methods.d
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
import std.algorithm;
|
||||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
immutable scores = [
|
||||
"Solomon": 44,
|
||||
"Jason": 42,
|
||||
"Errol": 42,
|
||||
"Garry": 41,
|
||||
"Bernard": 41,
|
||||
"Barry": 41,
|
||||
"Stephen": 39
|
||||
];
|
||||
|
||||
scores.standardRank;
|
||||
scores.modifiedRank;
|
||||
scores.denseRank;
|
||||
scores.ordinalRank;
|
||||
scores.fractionalRank;
|
||||
}
|
||||
|
||||
/*
|
||||
Standard ranking
|
||||
1 44 Solomon
|
||||
2 42 Jason
|
||||
2 42 Errol
|
||||
4 41 Garry
|
||||
4 41 Bernard
|
||||
4 41 Barry
|
||||
7 39 Stephen
|
||||
*/
|
||||
void standardRank(const int[string] data) {
|
||||
writeln("Standard Rank");
|
||||
|
||||
int rank = 1;
|
||||
foreach (value; data.values.dup.sort!"a>b".uniq) {
|
||||
int temp = rank;
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
writeln(temp, " ", v, " ", k);
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln;
|
||||
}
|
||||
|
||||
/*
|
||||
Modified ranking
|
||||
1 44 Solomon
|
||||
3 42 Jason
|
||||
3 42 Errol
|
||||
6 41 Garry
|
||||
6 41 Bernard
|
||||
6 41 Barry
|
||||
7 39 Stephen
|
||||
*/
|
||||
void modifiedRank(const int[string] data) {
|
||||
writeln("Modified Rank");
|
||||
|
||||
int rank = 0;
|
||||
foreach (value; data.values.dup.sort!"a>b".uniq) {
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
writeln(rank, " ", v, " ", k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln;
|
||||
}
|
||||
|
||||
/*
|
||||
Dense ranking
|
||||
1 44 Solomon
|
||||
2 42 Jason
|
||||
2 42 Errol
|
||||
3 41 Garry
|
||||
3 41 Bernard
|
||||
3 41 Barry
|
||||
4 39 Stephen
|
||||
*/
|
||||
void denseRank(const int[string] data) {
|
||||
writeln("Dense Rank");
|
||||
|
||||
int rank = 1;
|
||||
foreach (value; data.values.dup.sort!"a>b".uniq) {
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
writeln(rank, " ", v, " ", k);
|
||||
}
|
||||
}
|
||||
rank++;
|
||||
}
|
||||
|
||||
writeln;
|
||||
}
|
||||
|
||||
/*
|
||||
Ordinal ranking
|
||||
1 44 Solomon
|
||||
2 42 Jason
|
||||
3 42 Errol
|
||||
4 41 Garry
|
||||
5 41 Bernard
|
||||
6 41 Barry
|
||||
7 39 Stephen
|
||||
*/
|
||||
void ordinalRank(const int[string] data) {
|
||||
writeln("Ordinal Rank");
|
||||
|
||||
int rank = 1;
|
||||
foreach (value; data.values.dup.sort!"a>b".uniq) {
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
writeln(rank, " ", v, " ", k);
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln;
|
||||
}
|
||||
|
||||
/*
|
||||
Fractional ranking
|
||||
1,0 44 Solomon
|
||||
2,5 42 Jason
|
||||
2,5 42 Errol
|
||||
5,0 41 Garry
|
||||
5,0 41 Bernard
|
||||
5,0 41 Barry
|
||||
7,0 39 Stephen
|
||||
*/
|
||||
void fractionalRank(const int[string] data) {
|
||||
writeln("Fractional Rank");
|
||||
|
||||
int rank = 0;
|
||||
foreach (value; data.values.dup.sort!"a>b".uniq) {
|
||||
real avg = 0;
|
||||
int cnt;
|
||||
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
rank++;
|
||||
cnt++;
|
||||
avg+=rank;
|
||||
}
|
||||
}
|
||||
avg /= cnt;
|
||||
|
||||
foreach(k,v; data) {
|
||||
if (v==value) {
|
||||
writef("%0.1f ", avg);
|
||||
writeln(v, " ", k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue