TOPIC
Wrong anser 20% - Javascript
rlorandi asked 3 years ago
Alguma sugestão?
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var Amount, Type, C = 0, R= 0, S = 0, total = 0;
//number of test
var N = parseInt(lines.shift());
xyz = lines.shift().split(' ');
for(i = 0; i < N; i++)
{
var Amount = parseInt(xyz.shift());
var Type = xyz.shift();
if(i< N-1){
xyz = lines.shift().split(' ');
}
if(Type == 'C\r')
{
C += Amount;
total += Amount;
}
else if(Type == 'R\r' )
{
R += Amount;
total += Amount;
}
else if(Type == 'S\r' )
{
S += Amount;
total += Amount;
}
}
percentual_coelhos = C/total * 100;
percentual_ratos = R/total * 100;
percentual_sapos = S/total * 100;
console.log('Total: ' + total + ' cobaias');
console.log('Total de coelhos: '+ C);
console.log('Total de ratos: '+ R);
console.log('Total de sapos: '+ S);
console.log('Percentual de coelhos: '+ percentual_coelhos.toFixed(2) + ' %');
console.log('Percentual de ratos: '+ percentual_ratos.toFixed(2) +' %');
console.log('Percentual de sapos: '+ percentual_sapos.toFixed(2) +' %' );