Created
July 2, 2012 20:34
-
-
Save solomon081/3035540 to your computer and use it in GitHub Desktop.
rank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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