Skip to content

Commit

Permalink
Problem 10038
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanStarkey committed Apr 10, 2013
1 parent 9ba4471 commit 0bf4599
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
57 changes: 57 additions & 0 deletions uva10038.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* UVa Online Judge - Problem 10038 - Jolly Jumpers
*/

#include <iostream>
#include <vector>
#include <algorithm>

int absDiff(int x, int y)
{
if (x < y)
return y - x;
else
return x - y;
}

int main()
{
while (std::cin.good())
{
unsigned numberOfInts;
std::cin >> numberOfInts;
if (!std::cin.good())
break;

std::vector<int> ints;
for (int i=0; i<numberOfInts; i++)
{
int nextInt;
std::cin >> nextInt;
ints.push_back(nextInt);
}

std::vector<int> abs;
for (int i=0; i<(numberOfInts-1); i++)
{
abs.push_back(absDiff(ints[i], ints[i+1]));
}

bool jolly = true;
std::sort(abs.begin(), abs.end());
for (int i=0; i<(numberOfInts-1); i++)
{
if (abs[i] != (i+1))
{
jolly = false;
break;
}
}

if (jolly)
std::cout << "Jolly" << std::endl;
else
std::cout << "Not jolly" << std::endl;
}
return 0;
}
2 changes: 2 additions & 0 deletions uva10038.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
4 1 4 2 3
5 1 4 2 -1 6

0 comments on commit 0bf4599

Please sign in to comment.