fork(4) download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int abs(int a, int b);
  8.  
  9. int main()
  10. {
  11. queue<int> numeros, diferenca;
  12. int n, numero1, numero2, nLista[3003], nEntrada;
  13. bool jolly;
  14. char entrada;
  15.  
  16. do
  17. {
  18. jolly = true;
  19.  
  20. for(int i = 0; i < 3003; i++)
  21. nLista[i] = 0;
  22.  
  23. while(!numeros.empty())
  24. numeros.pop();
  25. while(!diferenca.empty())
  26. diferenca.pop();
  27.  
  28.  
  29. scanf("%d", &n);
  30.  
  31. do
  32. {
  33.  
  34. entrada = cin.peek();
  35.  
  36. if( (entrada != ' ') && (entrada != '\n') && (entrada != EOF) )
  37. {
  38. scanf("%d", &nEntrada);
  39. numeros.push(nEntrada);
  40. }
  41.  
  42. else
  43. entrada = getchar();
  44.  
  45. }while( (entrada != '\n') && (entrada != EOF) );
  46.  
  47. while(!numeros.empty())
  48. {
  49. numero1 = numeros.front();
  50. numeros.pop();
  51. if(!numeros.empty())
  52. {
  53. numero2 = numeros.front();
  54.  
  55. diferenca.push(abs(numero1, numero2));
  56. }
  57. }
  58.  
  59. while(!diferenca.empty())
  60. {
  61. if(diferenca.front() <= 3002)nLista[diferenca.front()] = 1;
  62. diferenca.pop();
  63. }
  64.  
  65. for(int i = 1; i <= (n - 1); i++)
  66. if(nLista[i] != 1)
  67. jolly = false;
  68.  
  69. if(jolly)
  70. printf("Jolly");
  71. else
  72. printf("Not jolly");
  73.  
  74. if(entrada != EOF)
  75. printf("\n");
  76.  
  77. }while(entrada != EOF);
  78.  
  79.  
  80. return 0;
  81. }
  82.  
  83. int abs(int a, int b)
  84. {
  85. int dif;
  86. dif = (a - b);
  87. dif = (dif >= 0)?dif : -dif;
  88. return dif;
  89. }
Success #stdin #stdout 0.02s 2864KB
stdin
4 1 4 2 3
5 1 4 2 -1 6
stdout
Jolly
Not jolly
Not jolly