Created
June 14, 2012 18:10
-
-
Save srinathgs/2931889 to your computer and use it in GitHub Desktop.
Revisions
-
srinathgs created this gist
Jun 14, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #include <iostream> #include <vector> #include <sstream> using namespace std; int main() { string buf; int n; while(true){ getline(cin,buf); //read ONE full line if(buf.empty()){ break; } istringstream inp(buf); // input string stream to read the full line input inp>>n; vector<bool> diffNums(n,false); bool jollyJump = true; int prev,curr; inp>>prev; for(int i = 1;i < n;i++){ int diff; inp>>curr; if(!curr>0){ jollyJump = false; // number < 0 break; } diff = prev > curr ? prev - curr : curr - prev; // find the difference (We can use abs function in cmath) if(diff<=0 || diff >= n || diffNums[diff-1]){ jollyJump = false; // difference is not valid. break; } diffNums[diff-1] = true; prev = curr; } cout<< (jollyJump?"Jolly":"Not jolly") <<endl; //print result } return 0; }