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 #5? Whats wrong with my code?
Posted by Dormidont3 17 Jan 2015 18:53
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int a[1000];
    int n,i,k;
    char Name;
    cin>>n;
    string B;
    k=0;
    for (i=0;i<n;i++){
        cin>>B;
        Name=B[0];
            if(Name=='A' or Name=='P' or Name=='O' or Name=='R') {a[i]=1;}
            else {if(Name=='B' or Name=='M' or Name=='S') {a[i]=2;}
                else {a[i]=3;};
                }
        }
    k=a[0]-1;

    for (i=1;i<n;i++){
        if (a[i-i]<a[i]){ k=k+a[i]-a[i-1];}
        else { k=k+a[i-1]-a[i];}

        }
    cout<<k;
        return 0;

}