Created
February 29, 2016 05:09
-
-
Save nkjzm/2d695e71809ad6bb489b to your computer and use it in GitHub Desktop.
ハッカソンの順位とチーム数から偏差値を求めるプログラム
This file contains hidden or 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
#include <iostream> | |
#include <math.h> | |
float GetAverageRank(int teamNum) | |
{ | |
float sum = 0; | |
for(int i=1; i<=teamNum; ++i) | |
{ | |
sum += i; | |
} | |
return sum/teamNum; | |
} | |
float GetStandardDeviation(int teamNum, float average) | |
{ | |
float sum = 0; | |
for(int i=1; i<=teamNum; ++i) | |
{ | |
sum += powf(i-average, 2); | |
} | |
return sqrtf(sum/teamNum); | |
} | |
float GetDeviation(int rank, int teamNum) | |
{ | |
float average = GetAverageRank(teamNum); | |
float standardDeviation = GetStandardDeviation(teamNum, average); | |
return -(((rank-average)*10)/standardDeviation) + 50; | |
} | |
int main() | |
{ | |
while(true) | |
{ | |
std::string eventName; | |
int rank,teamNum; | |
std::cout << "イベント名:"; | |
std::cin >> eventName; | |
std::cout << "順位:"; | |
std::cin >> rank; | |
std::cout << "参加チーム数:"; | |
std::cin >> teamNum; | |
std::cout << eventName << "での偏差値は" << GetDeviation(rank,teamNum) << std::endl; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment