Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///BISMILLAHIR-RAHMANIR-RAHIM
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int t, n;
- scanf("%d", &t); //scanning number of test cases
- int i, j, count, len, max_count, dish;
- int *ara; //declaring integer pointer for an array
- int *dis_count; //another integer pointer for counting number of each distinct element
- int *items; //another integer pointer for storing dish no
- while(t--){
- scanf("%d", &n); //scanning array size
- ara = (int *) malloc(sizeof(int) * n); //dynamic memory allocation for the integer pointer
- dis_count = (int *) calloc(sizeof(int), 1005); //dynamic memory allocation for dis_count
- count = 0;
- for(i = 0; i < n; i++){
- scanf("%d", &ara[i]); //scanning array
- if(dis_count[ara[i]] == 0) count++;
- dis_count[ara[i]]++;
- }
- len = count;
- printf("total items: %d\n", len);
- items = (int *)malloc(sizeof(int) * len); //dynamic memory allocation for items
- for(i = 0, j = 0; i <= 1000; i++){
- if(dis_count[i] != 0){
- items[j] = i; //storing items
- j++;
- }
- }
- max_count = 0;
- for(i = 0; i < len; i++){
- count = 0;
- for(j = 0; j < n; ){
- if(items[i] == ara[j] && ara[j+1] != ara[j] && ara[j] != ara[j - 1]){
- count++; //counting under condition
- j+=2;
- }
- else if(items[i] == ara[j]){
- j += 2;
- }
- else j++;
- }
- if(count > max_count){
- max_count = count; //preserving maximum number of count
- dish = items[i]; //preserving according dish number
- }
- }
- printf("%d\n", dish);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement