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

WA#3; what's wrong with my code, I am losing all my mind. :'(
Posted by Neeraj Kumar 18 Apr 2015 20:54
#include <iostream>
int main(void){

char nameOfKid[8];

int noOfLetters;
std::cin >> noOfLetters;
std::cin.ignore( 256, '\n') ;
int cur, temp, steps, newcur;
newcur = 0; cur = 0; steps= 0 ;
for (int i = 0 ; i < noOfLetters; ++i){

        std::cin.getline(nameOfKid, 8);

        temp = static_cast<int>(nameOfKid[0]);

        switch(temp){
            case 65:
            case 80:
            case 79:
            case 82: newcur = 1;
                   break;
            case 66:
            case 77:
            case 83: newcur = 2;
                   break;
            case 68:
            case 71:
            case 74:
            case 75:
            case 84: newcur = 3;
                   break;

        }
        if ((newcur!=cur) && (i!=0)){
        steps = steps + ((newcur>cur) ? (newcur-cur): (cur-newcur));

        }
        cur = newcur;

    }

std::cout << steps;
return 0;
}
Re: WA#3; what's wrong with my code, I am losing all my mind. :'(
Posted by Egor 15 Sep 2015 02:17
You can store first letters with their's corresponding place like that:

int m[256];
m['A'] = m['P'] = m['O'] = m['R'] = 1;
m['B'] = m['M'] = m['S'] = 2;
m['D'] = m['G'] = m['J'] = m['K'] = m['T'] = m['W'] = 3;
Re: WA#3; what's wrong with my code, I am losing all my mind. :'(
Posted by Dam Debotush 6 May 2019 02:26
#include<bits/stdc++.h>

using namespace std;

int main(){
    map<char,int>mp;
    mp['A'] = 1;
    mp['O'] = 1;
    mp['R'] = 1;
    mp['P'] = 1;

    mp['B'] = 2;
    mp['M'] = 2;
    mp['S'] = 2;

    mp['D'] = 3;
    mp['G'] = 3;
    mp['J'] = 3;
    mp['K'] = 3;
    mp['T'] = 3;
    mp['W'] = 3;

    int n,ans=0,pre=-1;
    string s;
    cin>>n;

    while(n--){
        cin>>s;
        if(pre== -1){
            pre = mp[s[0]];
        }else{
            ans += abs(mp[s[0]] - pre);
            pre = mp[s[0]];
        }
    }
    cout<<ans<<endl;

return  0;
}
i also got WA#3 doing in same way.