Algorithm


Problem Name: beecrowd | 1848

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1848

Counting Crow

 

By Emilio Wuerges, UFFS BR Brazil

Timelimit: 1

As we know, there's a three-eyed crow. What it isn't well known is that the three-eyed crow can foresaw the results of Westeros lottery. Meanwhile every other crow is flying collecting entries for the lottery, the three-eyed crow already knows the results, and when Bran dreams with the three-eyed crow, the crow tells him the result. Bran always remember these dreams very well, however, he can't understand them fast enough to know the result. Your task is write a program to calculate the result from Bran's dream.

During the dream, the crow blinks many times and screams exactly 3 times. Every scream corresponds to a result.

Every blink of the crow communicates a binary number. An open eye means 1 and a closed eye means 0. The left eye is the most significative eye and the right eye is the least significative eye. Every blink this number is added and when the crow screams, the sum is a result.

 

Input

 

The input describes, in every line, in order, a scream or a blink of the crow.

A scream is represented by the string caw caw.

A blink is formed by three characters * ou -, representing, respectively, an open eye or a closed eye, from left to right.

Remember that the crow has 3 eyes.

The winning numbers at lottery do not exceed 1000.

 

Output

 

The output are 3 lines, each one with one result of the lottery.

 

 

 

Input Sample Output Sample
--*
caw caw
*--
caw caw
caw caw
1
4
0

 

Input Sample Output Sample
--*
--*
--*
caw caw
*--
*--
caw caw
--*
*--
caw caw
3
8
5

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int count =1,sum=0;
    while(count  < = 3)
    {
        getline(cin,str);
        if(str[0]=='c')
        {
            cout << sum << endl;
            count++;
            sum=0;
        }
        else
        {
            if(str=="---")
                sum+=0;
            else if(str=="--*")
                sum+=1;
            else if(str=="-*-")
                sum+=2;
            else if(str=="-**")
                sum+=3;
            else if(str=="*--")
                sum+=4;
            else if(str=="*-*")
                sum+=5;
            else if(str=="**-")
                sum+=6;
            else if(str=="***")
                sum+=7;
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
--* caw caw *-- caw caw caw caw

Output

x
+
cmd
1 4 0

#2 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
 var count = 0;
 var total = 0;
 while(count!=3){
     var value = lines.shift();
     if(/caw/i.test(value)){
         console.log(total);
         total = 0;
         count++;
     }else{
         var binary = '';
         for(var i = 0; i < value.length; i++){
             if(value[i]=='*'){
                 binary += '1';
             }else{
                 binary += '0';
             }
         }
         var num = parseInt(binary,2>;
         total += num;
     }
 }
Copy The Code & Try With Live Editor

Input

x
+
cmd
--* caw caw *-- caw caw caw caw

Output

x
+
cmd
1 4 0
Advertisements

Demonstration


Previous
#1847 Beecrowd Online Judge Solution 1847 Welcome to the Winter! Solution in C++, Java, Js and Python
Next
#1849 Beecrowd Online Judge Solution 1849 Dracarys! Solution in C, C++, Java, Js and Python