Skip to content

Instantly share code, notes, and snippets.

@duyet
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save duyet/eb879977f41c64bf3a0a to your computer and use it in GitHub Desktop.

Select an option

Save duyet/eb879977f41c64bf3a0a to your computer and use it in GitHub Desktop.
#define MAX 1000
int main() {
FILE *input, *output;
int n; // Số lượng phần tử n
int array[MAX]; // Mảng aray chứa n số tiếp theo
input = fopen("input.txt","rt"); // Mở file input
fscanf(input,"%d",&n); // Nhập giá trị n
for (int i = 0; i < n; ++i) {
fscanf(f,"%d",&array[i]); // Lấy n số hạng
}
// Sắp xếp tăng dần
sort(array);
int rangle[MAX]; // mảng chứa hạng của từng số
/*
Ví dụ:
1, 1, 2, 2, 6, 6, 6, 9
-------
==> a = 6, b = 4
Bây giờ tìm số a là tìm giá trị c dãy trùng dài nhất: 6, 6, 6
Tìm b là tìm số dãy khác nhau (4 )
*/
int max_len = 1; int a = array[0];
for (int i = 1; i < n; i++) {
int max_len_of_current = 1;
for (int j = i + 1; j < n; j++) {
if (array[j] == array[i]) {
max_len_of_current++;
if (max_len_of_current >= max_len) {
max_len = max_len_of_current;
a = array[j];
}
}
}
}
int b = 0;
for (int i = 0; i < n; i++) {
b += 1;
int j = i + 1;
while (array[i] == array[j]) j++;
i = j;
}
// OUTPUT
fprintf(output, "%d %d", a, b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment