Codeforces Solution 3A-Shortest Path Of The King - Solution in C++ - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, May 2, 2017

Codeforces Solution 3A-Shortest Path Of The King - Solution in C++

Codeforces Solution 3A-Shortest Path Of The King - Solution in C++


CodeForces Online Judge Solution  3A-Shortest Path Of The King
CodeForces Main Problem Link - 3A-Shortest Path Of The King

Problem Name: CodeForces Problem 3A-Shortest Path Of The King
Problem Number : CodeForces Problem 3A-Shortest Path Of The King Solution
Online Judge : CodeForces Online Judge Solution
Category: Math
Solution Language : C plus plus

CodeForces Solution 3A-Shortest Path Of The King Code in CPP:


#include <cstdio>
#include <iostream>

int main(){
    std::string source, dest;
    getline(std::cin, source); getline(std::cin,dest);
    int horDist, verDist; char horLet, verLet;
    
    if(source[0] < dest[0]){horDist = dest[0] - source[0]; horLet = 'R';}
    else{horDist = source[0] - dest[0]; horLet = 'L';} 

    if(source[1] < dest[1]){verDist = dest[1] - source[1]; verLet = 'U';}
    else{verDist = source[1] - dest[1];verLet = 'D';}

    int numMoves = std::max(horDist, verDist);printf("%d\n", numMoves);
    
    while(numMoves--){
        if(--horDist >= 0){std::cout << horLet;}
        if(--verDist >= 0){std::cout << verLet;}
        std::cout << std::endl;
    }
    return 0;
}

No comments:

Post a Comment