-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ba4471
commit 0bf4599
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |