Hướng dẫn giải của TS10 Quảng Ninh 2023 - Tọa độ

Chỉ dùng lời giải này khi không có ý tưởng, và đừng copy-paste code từ lời giải này. Hãy tôn trọng người ra đề và người làm lời giải.


Nộp code mẫu trước khi tự giải được bài tập là một hành vi có thể bị ban.

Tác giả: bachminhkhang

Code tham khảo

#include<bits/stdc++.h>
#define reu(i,a,b) for(int i=a,_b=b;i<=_b;++i)
#define red(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define iii pair<int,pair<int,int> >
#define sz(x) int(x.size())
using namespace std;
//const int N= ;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, -1, 0, 1};

string s;
int a[100], x = 0, y = 0;

void input()
{
    cin >> s;
    a[int('E')] = 0;
    a[int('S')] = 1;
    a[int('W')] = 2;
    a[int('N')] = 3;
}

void solve()
{
    for(auto &c : s)
    {
        x += X[a[int(c)]];
        y += Y[a[int(c)]];
    }
    cout << x << ' ' << y;
}

int main()
{
    freopen("coor.inp","r",stdin);
    freopen("coor.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    input();
    solve();
    return 0;
}

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.