Advertisement
Guest User

Untitled

a guest
Sep 17th, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <stack>
  7. #include <bitset>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <numeric>
  11. #include <utility>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <cstdio>
  16. #include <cmath>
  17. #include <cstdlib>
  18. #include <ctime>
  19.  
  20. using namespace std;
  21.  
  22. class RouteIntersection {
  23. public:
  24.     string isValid(int, vector <int>, string);
  25. };
  26.  
  27. string RouteIntersection::isValid(int N, vector <int> coords, string moves) {
  28.     int ss = coords.size();
  29.     for(int i = 0; i < ss; i++ ){
  30.         map<int, int> values;
  31.         int cnt_repeat = 0;
  32.         for(int j = i; j < ss; j++ ){
  33.             if(moves[j] == '+'){
  34.                 int temp = ++values[coords[j]];
  35.                 if(temp == 1) cnt_repeat++;
  36.                 else if(temp == 0) cnt_repeat--;
  37.             } else {
  38.                 int temp = --values[coords[j]];
  39.                 if(temp == -1) cnt_repeat++;
  40.                 else if(temp == 0) cnt_repeat--;
  41.             }
  42.             if(cnt_repeat == 0) return "NOT VALID";
  43.         }
  44.     }
  45.     return "VALID";
  46. }
  47.  
  48. <%:testing-code%>
  49. //Powered by [KawigiEdit] 2.0!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement