fork download
  1. #include <iostream>
  2. #include <numeric>
  3. #include <iomanip>
  4. #include <cmath>
  5. #include <climits>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. const int MOD = (int)(1e9 + 7);
  11.  
  12. bool isPrime(long long n) {
  13. for (long long i = 2;i * i <= n;i++) {
  14. if (n % i == 0) {
  15. return false;
  16. }
  17. }
  18. return n >= 2;
  19. }
  20.  
  21. int main() {
  22. int t;cin >> t;
  23. for (int q = 1;q <= t;q++) {
  24. int n;cin >> n;
  25. vector<int> v;
  26. for (int i = 0;i < n;i++) {
  27. int value;cin >> value;
  28. v.push_back(value);
  29. }
  30.  
  31. int current_length = 1, max_length = 1;
  32.  
  33. int sub[1000];
  34. int numberOfSubArray = 1;
  35. sub[0] = 0;
  36.  
  37. for (int i = 1;i < n;i++) {
  38. if (v[i] > v[i - 1]) {
  39. current_length++;
  40. }
  41. else {
  42. current_length = 1;
  43. }
  44.  
  45. if (current_length > max_length) {
  46. max_length = current_length;
  47. numberOfSubArray = 1;
  48. sub[0] = i - max_length + 1;
  49. }
  50. else if (current_length == max_length) {
  51. sub[numberOfSubArray] = i - max_length + 1;
  52. numberOfSubArray++;
  53. }
  54. }
  55.  
  56. cout << "Test #" << q << " : " << endl;
  57. cout << max_length << endl;
  58. for (int i = 0;i < numberOfSubArray;i++) {
  59. // In ra dãy con có max_length phần tử bắt đầu từ vị trí sub[i]
  60.  
  61. for (int j = 0;j < max_length;j++) {
  62. cout << v[sub[i] + j] << " ";
  63. }
  64. cout << endl;
  65. }
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty