Monday, May 1, 2017

URI Solution 1228 Start Grid - Solution in C++ | Ad Hoc

URI Solution 1228 Start Grid - Solution in C++ | Ad Hoc


URI Online Judge Solution Start Grid  | Ad Hoc
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1228

Problem Name: URI Problem Start Grid
Problem Number : URI - 1228
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1228 Code in CPP:

#include <cstdio>
#include <algorithm>

using namespace std;

int s[25], f[25];

int lookup(int n, int x)
{
 for (int i = 0; i < n; ++i)
  if(s[i] == f[x])
   return i;

 return -1;
}

int main(int argc, char const *argv[])
{
 int n, i, c, tmp;

 while(scanf("%d", &n) == 1)
 {
  for (i = 0; i < n; ++i)
   scanf("%d", &s[i]);

  for (i = 0; i < n; ++i)
   scanf("%d", &f[i]);

  i = 0; c = 0;

  while(i < n)
  {
   while(s[i] != f[i])
   { 
    tmp = lookup(n, i);
    swap(s[tmp - 1], s[tmp]);
    c++;
   }
   i++;
  }

  printf("%d\n", c);
 }

 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.