ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2023. Donald is a postman

TEST #3
Posted by GALIAF95 11 Oct 2014 16:28
Here is the code(c++), what is wrong?

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string name[1001];
    int counter=0;
    int n,i=0;
    cin>>n;
    while(i<=n)
    {
        getline(cin,name[i]);
        if(i!=0)
            if(name[i-1][0]!=name[i][0])
                if(name[i-1][0] == 'A' || name[i-1][0] == 'P'||name[i-1][0] == 'O'||name[i-1][0] == 'R')
                {
                    if(name[i][0] == 'B' || name[i][0] == 'M'||name[i][0] == 'S')
                        counter++;
                    else
                        counter+=2;
                }
                else if(name[i-1][0] == 'B' || name[i-1][0] == 'M'||name[i-1][0] == 'S')
                {
                    counter++;
                }
                else if(name[i-1][0] == 'D' || name[i-1][0] == 'G'||name[i-1][0] == 'J'||name[i-1][0] == 'K'||name[i-1][0] == 'T'||name[i-1][0] == 'W')
                {
                    if(name[i][0] == 'B' || name[i][0] == 'M'||name[i][0] == 'S')
                        counter++;
                    else
                        counter+=2;
                }
        i++;
    }
    cout<<counter;
}
Re: TEST #3
Posted by Someone Else 20 Dec 2014 13:40
Use a map instead of many "if"s.