CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

int main(){

int number;
cin>>number;

int InputArray[number];

for (int i=0;i<number;i++){
    cin>>InputArray[i];
}

int FrequencyArray[number];
for (int i=0;i<number;i++){
    FrequencyArray[i]=0;
}


for (int i=0;i<number;i++){
    for(int j=0;j<number;j++)
    {
        if (InputArray[j]==InputArray[i]) FrequencyArray[i]++;
    }
}

int MaxFrequency=0,Position=0;

for (int i=0;i<number;i++){
if (FrequencyArray[i] > MaxFrequency){
    Position=i;
    MaxFrequency = FrequencyArray[i];
}
}

cout<<InputArray[Position]<<" "<<MaxFrequency;

}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for (int i=0;i<n;i++)
{
cin>>a[i];
}
int count[n];
for (int i=0;i<n;i++) count[i]=1;
for (int i=0;i<n;i++)
{
 for (int j=0;j<i;j++)
{
 if(a[i]==a[j]) count[i]++;
 else continue;
}
}
int maxindex =0;
for (int i=0;i<n;i++)
{
if (count[maxindex]<count[i]) maxindex=i;
}
cout<<a[maxindex]<<' '<<count[maxindex];
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main(){
int n,m;
cin>>n;
m = left(n);
cout<<"m";
return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include <iostream>
using namespace std;
int main(){
int a[20]={0};
int b[20]={0};
int max=0;
int n;
cin>>n;
for(int i=0;i<n;i++){cin>>a[i];}
for(int i=0;i<n;i++){for(int j=0;j<n;j++){if(a[i]==a[j]){b[i]++;}}}
for(int i=0;i<n;i++){if(b[i]>b[max]){max=i;}}
cout<<a[max]<<" "<<b[max];}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

int maxph(int *arr,int n){
    int val=arr[0];
    int ph=0;
    for (int i=0;i<n;i++){
        if (arr[0]<arr[i]){
            val ++;
            ph=i;
        }
    }
    return ph;
}

int main (){
    int n;
    cin >> n;
    int rarr[n];
    for (int i=0;i<n;i++){
        cin >> rarr[i];
    }

    int psarr[n]={rarr[0]};
    int uq=1;
    for (int i = 1;i<n;i++){
        int j=0;
        while (j<uq){
            bool same = (psarr[j]==rarr[i]);
            if (same){break;}
            j++;
        }
        if (j==uq-1){
            psarr[i]=rarr[i];
            uq++;
        }
    }

    int parr[uq];
    for (int i=0;i<uq;i++){
        parr[i]=psarr[i];
    }

    int carr[uq];
    for (int i=0;i<uq;i++){
        carr[i]=0;
        for (int j=0;j<n;j++){
            if (parr[i]==rarr[j]){
                carr[i]++;
            }
        }
    }

    int ansph=maxph(carr,uq);
    cout << parr[ansph]<< " " <<carr[ansph];
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<simplecpp>
main_program{
	int n,i,a=0,b=0,c=0;
	cin>>n;
	int A[n];
	
	for(i=0;i<n;i++){
		cin>>A[i];
	}
	
	for(i=0;i<n;i++){
		if(A[i]==1){
			a=a+1;
			}
	}
	if(A[0]==1){
			cout<<1<<" "<<a;
		}
	
	for(i=0;i<n;i++){
		if(A[i]==42){
			b=b+1;
			cout<<42<<" "<<b;
		}
	}
	
	for(i=0;i<n;i++){
		if(A[i]==3){
			c=c+1;
		}
		
	}
	if(A[0]==3){
		cout<<3<<" "<<c;
	}
	
	
		
		
		
		
	
	
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
  cin>>arr[i];}
  int i;
  i=0;
  int b=0;
  
while(b<n){
	if(arr[1]==arr[b]) {
	 
	i++;
  }
  b++;
  
  }
  
  cout<<arr[i]<<endl;
  cout<<i;


}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main()
{   
    int n;
    cin>>n;
    
 int  array[n];
   for(int i=0;i<n;i++){
   cin>>array[i]>>" ";
   }
   
   for(int i=0;i<n;i++){
    if(array[i]==array[i+1]){
     cout<<array[i]<<" "<<"2"<<endl;
     }
     else{
     cout<<array[i]<<" "<<endl;
     }
  }
  return 0;
  }

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

int main()
{

int n;
cin>>n;
int farr[n];
int arr[n];
for(int i = 0; i<n; i++)
{
farr[i] = 0;
cin>>arr[i];
}



for(int i = 0; i<n; i++)
{
if(arr[i] == -1)
{continue;}

int curr = arr[i];
farr[i] += 1;


for(int j = i+1; j<n; j++)
{
if(arr[j] == curr)
{
farr[i]+=1;
arr[j] = -1;
}


}


}



int maxi = 0;
int maxx = -5;
for(int p = 0; p<n; p++)
{

if(farr[p]>maxx)
{
maxx = farr[p];
maxi = p;
}



}

cout<<arr[maxi]<<' '<<farr[maxi];

return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include <iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int arr1[n],arr2[n];
	for (int i = 0; i<n; i++){
		cin >> arr1[i];
		arr2[i]=1;
	}
	for (int i = 0; i<n-1;i++){
		for (int j = i+1; j<n;j++){
			if (arr1[i]==arr1[j]){
				arr2[j]+=arr2[i];
				arr2[i]=0;
				break;
			}
		}
	}
	int max_val = 0, max_index=-1;
	for (int i = 0; i<n; i++){
		if (arr2[i]>max_val){max_index=i;max_val=arr2[i];}
	}
	cout << arr1[max_index]<<" "<<arr2[max_index];
	return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

int maxpos(int a[],int n){
int p=0;
for(int i=0;i<n;i++){if(a[p]<a[i])p=i;}
return p;
}

int main(){
int n;cin>>n;
int a[n],c[n];
for(int i=0;i<n;i++){cin>>a[i];c[i]=1;}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(a[i]==a[j]){c[j]++;break;}
}
}
cout<<a[maxpos(c,n)]<<" "<<c[maxpos(c,n)];


return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

void majorityelements( int* p, int n)
{int c=0;
int d=0;
int x=p[0];
int temp=0;
for (int i=n-1;i>=0;i--)
{for(int j=0;j<i;j++)
{
if(p[j+1]>p[j])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}

for(int i=0;i<n-1;i++)
{if(p[i]!=p[i+1])
{if(i-c+1>=d)
{
d=i-c+1;
x=p[i];
}
c=i;
}
}
if(n-1-c>=d)
{d=n-c-1;
x=p[n-1];
}
if(c==0)
{d=n-c;
x=p[n-1];
}
cout<<x<<" "<<d;

}

void inputArray(int* p, int n)
{for(int i=0;i<n;i++)
cin>>p[i];
}

int main()
{int n;
cin>>n;
int arr[n];
inputArray(arr,n);
majorityelements(arr,n);
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<simplecpp>
main_program{
int n,x=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
int g;
cin>>g;
a[i]=g;}
int maxindex=0;
for(int j=0;j<n;j++){
 if(a[maxindex]<a[j]) maxindex=j;}
cout<<a[maxindex]<<" ";
for(int h=0;h<n;h++){
if(a[maxindex]==a[h])x++;}
cout<<x;}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n],b[n];
	for (int k=0;k<n;k++){
		b[k]=0;
	}
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int j=0;j<n;j++){
		int c=a[j];
		for (int i=0;i<n;i++){
			if (c==a[i]){
				b[j]++;
			}
		}
	}
	int max=0,max_index;
	for (int k=0;k<n;k++){
		if (max<b[k]){
			max=b[k];
			max_index=k;
		}
	}
	cout<<a[max_index]<<" "<<max;
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int f(int x,int n,int *a){
int c=0;
for(int i=0;i<n;i++){
if(a[i]==x) c+=1;}
return c;}
int main(){
int n;
cin>>n;
int a[n],b[n];
for(int i=0;i<n;i++){
cin>>a[i];
b[i]=0;}
for(int j=0;j<n;j++){
 b[j]=f(a[j],n,a);
}
int x,t=0;
for(int i=0;i<n;i++)
{ if(b[i]>t) {x=i;t=b[i];}
}
cout<<a[x]<<" "<<t;
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include <iostream>
#include <cmath>
using namespace std;
int main (){
	int n;
	cin >> n;
	int a[n], b[n];
	for (int x=0; x<n; x++)
	{cin >> a[x];}
	for (int y=0; y<n; y++)
	{ b[y]=0;}
	for (int i=0; i<n; i++)
	{
		for (int j=i+1;j<n; j++)
	{ if (a[i]==a[j]) b[i]++;}
	}
	for (int k=0; k<n; k++)
	{
		if (b[k]>b[k+1])
		{
			b[k+1]=b[k];
			a[k+1]=a[k];
		}
		
	}
	
	cout << a[n-1] << " " << b[n-1]+1;
		
		
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int maxindex(int a[],int n)
{  int x=0;
   for(int i=0; i<n; i++)
   {  if(a[i]>a[x]) x=i;
   }
   return x;
}
int main()
{  int n;
   cin >> n;
   double array[n];
   int num[n];
   for(int i=0; i<n; i++)
   {  cin >> array[i];
      num[i]=0;
   }
   for(int i=0; i<n; i++)
   {  for(int j=i; j<n; j++)
      {  if(array[i]==array[j]) num[i]++;
      }
   }
   cout << array[maxindex(num,n)] << " ";
   cout << num[maxindex(num,n)];
}

Grading criterion: Quality of variable names
Rating A: Good Variables Names
Rating B: Ok Variable Names
Rating C: Poor Naming of Variables
Rating D: 0
Assigned grade: B