Skip to content

Instantly share code, notes, and snippets.

@solomon081
Created July 2, 2012 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solomon081/3035540 to your computer and use it in GitHub Desktop.
Save solomon081/3035540 to your computer and use it in GitHub Desktop.
rank
// rankclass.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Ranker
{
int up, down, views;
double age;
public:
void set_ranks(int, int, int, double);
int rankit();
};
void Ranker::set_ranks(int a, int b, int c, double d)
{
up = a;
down = b;
views = c;
age = d;
}
int Ranker::rankit()
{
// Returns zero if the post has more downvotes than upvotes
if (up < down)
{
return 0;
}
else
{
int result = up * 2 - down * 1.5;
result *= (up - down);
// Makes sure the post isn't too new. If it is too new, the result might be huge.
if (age > 1)
{
result /= age;
}
if (views > 10000)
{
result++;
}
return int(result);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Ranker simple_ranker;
simple_ranker.set_ranks(30, 20, 100, 2);
cout << simple_ranker.rankit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment