Advertisement
Guest User

zad2

a guest
Feb 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, i=0, imax = 0, imaxp = 0;
  8. cin >> n;
  9. double tab[n];
  10. do{
  11. cin >> tab[i];
  12. if(tab[i] < 0)
  13. imaxp++;
  14. else{
  15. if(imaxp > imax)
  16. imax = imaxp;
  17. imaxp = 0;
  18. }
  19. i++;
  20. }while(i < n);
  21. double podciagi[n][imax];
  22. i = 0;
  23. int ipom = 0, ipom2 = 0;
  24. cout << endl;
  25. while(i < n){
  26. if(tab[i] < 0){
  27. podciagi[ipom][ipom2] = tab[i];
  28. ipom2++;
  29. cout << tab[i] << " ";
  30. }
  31. else{
  32. ipom++;
  33. ipom2 = 0;
  34. cout << endl;
  35. }
  36. i++;
  37. }
  38. cout << "\nciagi najdluzsze\n";
  39. i = 0, ipom = 0, ipom2 = 0;
  40. while(i < n){
  41. if(podciagi[ipom][ipom2] < 0)
  42. ipom2++;
  43. else{
  44. if(ipom2 == imax){
  45. for(int a = 0; a < imax; a++)
  46. cout << podciagi [ipom][a];
  47. }
  48. ipom++;
  49. ipom2 = 0;
  50. cout << endl;
  51. }
  52. i++;
  53. }
  54. return 0;
  55. }
  56.  
  57. /*
  58. Dany jest ciąg n-elementów liczb rzeczywistych. Napisz program
  59. który wypisze wszystkie podciagi liczb ujemnych. Wypisz także podciagi nadłuzsze spełniacjeace ten warunek
  60. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement