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

This is my solution, and it be Accepted, C++
Posted by Manh Le Van 20 Feb 2016 13:16
/*
Le Van Manh
Hanoi University Of Science And Technology
Viet Nam
*/
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int readAddressToValue(){
    int v = 0;
    string a;
    cin>>a;
    if(
        a=="Alice"||a=="Ariel"||a=="Aurora"||
        a=="Phil"||a=="Peter"||a=="Olaf"||
        a=="Phoebus"||a=="Ralph"||a=="Robin"){
        v = 0;
    }else
    if(
        a=="Bambi"||a=="Belle"||a=="Bolt"||
        a=="Mulan"||a=="Mowgli"||a=="Mickey"||
        a=="Silver"||a=="Simba"||a=="Stitch"){
        v = 1;
    }else{
        v = 2;
    }
    return v;
}
int main(){

    int address0;
    int address1;
    int steps = 0;
    int n;
    cin>>n;

    address0 = readAddressToValue();
    steps+= address0 - 0;
    for(int i=1;i<n;i++){
        address1 = readAddressToValue();
        steps += abs(address1 - address0);
        address0 = address1;
    }

    cout<<steps;
    return 0;
}

Edited by author 20.02.2016 13:17
Re: This is my solution, and it be Accepted, C++
Posted by ivan 8 Mar 2016 11:34
почему ворчит на abs
Re: This is my solution, and it be Accepted, C++
Posted by Mixail 23 Apr 2016 15:55
потому что не подключил <cmath>