Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <math.h>
- using namespace std;
- typedef struct pos{
- int x;
- int y;
- }pos;
- /// N E S W
- pos ctrl[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
- char cmd[110];
- int mov[4];
- int len, m, mx;
- void PrintMove(){
- for(int i = 0; i < 4; ++i){
- cout << mov[i] << " ";
- }
- cout << "\n";
- return;
- }
- int main(){
- pos c;
- int tmp;
- scanf(" %s", cmd);
- len = strlen(cmd);
- scanf("%d", &m);
- for(int i = 0; i < len; ++i){
- switch(cmd[i]){
- case 'N':
- ++mov[0];
- break;
- case 'E':
- ++mov[1];
- break;
- case 'S':
- ++mov[2];
- break;
- case 'W':
- ++mov[3];
- break;
- }
- }
- mx = 0;
- for(int n = 0; n <= m; ++n){
- if(mov[0] - n >= 0){
- for(int e = 0; e <= m - n; ++e){
- if(mov[1] - e >= 0){
- for(int s = 0; s <= m - n - e; ++s){
- if(mov[2] - s >= 0 && mov[3] - m + n + e + s >= 0){
- c = {0, 0};
- c.x += ctrl[0].x * (mov[0] - n);
- c.y += ctrl[0].y * (mov[0] - n);
- c.x += ctrl[1].x * (mov[1] - e);
- c.y += ctrl[1].y * (mov[1] - e);
- c.x += ctrl[2].x * (mov[2] - s);
- c.y += ctrl[2].y * (mov[2] - s);
- c.x += ctrl[3].x * (mov[3] - m + n + e + s);
- c.y += ctrl[3].y * (mov[3] - m + n + e + s);
- tmp = abs(c.x) + abs(c.y);
- mx = max(mx, tmp);
- }
- }
- }
- }
- }
- }
- cout << 2 * mx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement