Sirius
BAN USERpublic void main_test() throws IOException {
long starttime = System.nanoTime();
FileInputStream fis = new FileInputStream("input.txt");
try(InputStreamReader is = new InputStreamReader(fis)){
int ch;
int count = 0;
while((ch = is.read()) != -1){
if(ch == ' ' || ch == '\n')
count++;
}
long endtime = System.nanoTime();
System.out.println("count is "+(count+1)+"exec time is "+(endtime-starttime));
}
}
public void main_test1() throws FileNotFoundException{
long starttime = System.nanoTime();
try(Scanner fr = new Scanner(new File("input.txt"))){
int count = 0;
while(fr.hasNextLine()){
count += fr.nextLine().split(" ").length;
}
long endtime = System.nanoTime();
System.out.println("count is "+(count+1)+"exec time is "+(endtime-starttime));
}
}
outputs
count is 27543exec time is 55029484
count is 27543exec time is 124688369
junit times:
main_test: 0.048
main_test1: 0.126
decide for yourself whichone is better
if its synchronized lock is automatically removed and other thread continues to execute. if there is Lock mechanism we need the remove the lock explicitly in finally block. since there is no exception handling done this thread will have the lock and the program hangs. correct me if am wrong
- Sirius February 17, 2015really it is compiler dependent. check out of below code
A is -842150451 B is -842150451
x is 009294A0 y is 0092A038
int main_contr()
{
class a
{
int aaa;
public:
a()
{
}
int geta()
{
return aaa;
}
};
a* A = new a;
a* B = new a();
cout << "A is " << A->geta() << " B is " << B->geta();
int* x = new int;
int* y = new int();
cout << "\nx is " << x << " y is " << y;
return 0;
}
what if the number is really big like 100 digits
then we cant use int
here k is number of continuous digits
void findgreat(char* str, int k)
{
short len = strlen(str);
char buf[5] = { 0, };
char* begin = str;
char* end = str + len - 4;
char* index = NULL;
char max = *begin;
index = begin;
begin++;
while (begin != end)
{
if (*begin < max)
{
begin++;
}
else if (*begin == max)
{
if (strncmp(begin, index, k) > 0)
{
max = *begin;
index = begin;
begin++;
}
else
begin++;
}
else
{
max = *begin;
index = begin;
begin++;
}
}
for (short i = 0; i < 4; i++)
cout << index[i] << " ";
}
what if the given number is really big?
in that case you cant use an int to store the num
better to assume num is represented by string
k is number of continuous digits needed
void findgreat(char* str, int k)
{
short len = strlen(str);
char buf[5] = { 0, };
char* begin = str;
char* end = str + len - 4;
char* index = NULL;
char max = *begin;
index = begin;
begin++;
while (begin != end)
{
if (*begin < max)
{
begin++;
}
else if (*begin == max)
{
if (strncmp(begin, index, k) > 0)
{
max = *begin;
index = begin;
begin++;
}
else
begin++;
}
else
{
max = *begin;
index = begin;
begin++;
}
}
for (short i = 0; i < 4; i++)
cout << index[i] << " ";
}
for each players calculate win% first.
we can calculate relative grading for each player
first calculate standard deviation for win percentage and no of years
1.5(sd) = A+
1(sd) = A
0.5(sd) = B+
etc
now assign credits for win% and no of years played.
The weightage could be according to you.. you can assign more credits to win% like 5
and for experience you can assign 3.
5 and 3 are as per my judgement. It could be based on some studies or survey.
assume these are the grades for each player
player win% years
1 A A
2 A+ C
3 B B+
relative grading for player1 (5*9+3*9)/8 = 9
relative grading for player2 (5*10+3*6)/8 = 8.5
relative grading for player3 (5*7+3*8)/8 = 7.37
this way ranks can be calculated.
any comments are appreciated
- Sirius March 09, 2015