CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return -1;
if (second[i] == 0) return +1;
if (first[i] < second[i]) return -1;
if (first[i] > second[i]) return +1;
i++;
}
return 0;
}

void string_sort(char** A, int n, int &ns){
	for (int i=0; i<n; i++){
		int mi=i;
		for (int j=i+1; j<n; j++){
			if (string_compare(A[mi], A[j]) ==1 ){
				mi=j;
				}
			}
		swap(A[i], A[mi]); ns++;
		}				
	}


int main() {
int n, ns=0;  // ns - no of swaps
cin>>n;
char** A= new char*[n];   
for (int i=0; i<n+1; i++){
	A[i]=new char[11];
	}

for (int i=0; i<n+1; i++){
	cin.getline(A[i], 10);
}
string_sort(A, n, ns);
for (int i=n; i>=0; i--){
	cout<<A[i]<<endl;
	}
cout<<n*(n-1)*0.5<<endl<<ns;
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: B
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<simplecpp>

int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return -1;
if (second[i] == 0) return +1;
if (first[i] < second[i]) return -1;
if (first[i] > second[i]) return +1;
i++;
}
return 0;
}

main_program{
	int n;
	cin>>n;
	char A[n][11];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>A[i][j];
		}
	}
	
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<cstring>
#include<iostream>
using namespace std;
int string_compare(char *first, char *second)
{
int i=0; 
while(true)
{
if(first[i]==0&&second[i]==0)
return 0;
if(first[i]==0)
return -1;
if(second[i]==0)
return +1;
if(first[i]<second[i])
return -1;
if(first[i]>second[i])
return +1;
i++;
}
return 0;
}
void string_sort(char a[][12],int n)
{int q=0,s=0;
int i,j,d;
char c[12],c1[12];
for(i=0;i<n;i++)
{
int b=string_compare(a[i],c1);
q++;
if(b==-1)
{
char m[]=c;

}
char n=a[i][];
a[i]=l;
a[d]=n;
s++;
}
cout<<a;
}

int main()
{
int n;
cin>>n;
char a[n][12];
int i;
for(i=0;i<n;i++)
{
for(j=0;j<11;j++)
cin>>a[i][j];
}

string_sort(a,n);
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
#define MAX 100;
using namespace std;
int string_comparison(char string [MAX][MAX],int n){
for(int i=0;i<n-1;i++){
	for(int j=0;j<12j++){
		if(string[i][j]<string[i+1][j]) return 1;
		else if(string[i][j]>string[i+1][j]) return -1;
		else return 0;}
}
}
int length(char string[MAX])
	int l=0;
	while(string[l]!=0) l++;
	return l;}

void swap(char* s1,char* s2){
	char temp=*s1;
	*s1=*s2;
	*s2=temp;}
	void string_reverse(char string[MAX][MAX],int n){
		for(int i=0;i<n;i++){
			int l=string[i];
				int start=0;
				int end=l-1;
				while(start<=end){
					swap(string[i][start],string[i][end];
							start++;
							end--;}
		for(int k=0;k<l;k++){	cout<<string[i][k];}				
							}}
int main(){
	int n;
	cin>>n;
	char string[MAX][MAX];
	for (int i=0;i<n;i++){
		cin>>string[i];}
      string_comparison(string,n);
       string_reverse(string ,n);
       return 0;
       }

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

int string_compare (char*first, char*second){
int i=0;
while (true){
	if (first[i]==0 && second[i]==0) return 0;
	if (first[i]==0) return -1 ;
	if (second[i]==0) return +1;
	if (first[i] < second[i]) return -1 ;
	if (first[i] > second[i]) return +1 ;
	i++;
	}
return 0;
}


void selection_sort (float*data, int n){
for (int i=n; i>1; i--) {
	int maxindex=argmax(data, i) ;
	mySwap (&data[maxindex], &data[i-1]);
	}
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<simplecpp>
void bubble_sort(float *A, int n)
{
    int i, j;
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - i - 1; j++)
        {
            if (A[j] > A[j + 1])
                swap(&A[j], &A[j + 1]);
        }
    }
}

int string_compare (char *first, char * second){
	int i = 0;
	while (true){
		if (first[i] == 0 && second[i] == 0) return 0;
		if (first[i] == 0) return +1;
		if (second[i] == 0) return -1;
		if (first[i] < second[i]) return +1;
		if (first[i] > second[i]) return -1;
		i++;
	}
	return 0;
}
int max(char *A,int n){
	int arr[n],arr1[n];int x;
	for(int i=0;i<n;i++){
		int l=0;
		for(int j=0;j<n;j++){
			l=l+string_compare(A[i],A[j]);
		}
		arr[i]=l;
	}
	for(int i=0;i<n;i++){
		arr1[i]=arr[i];
	}
	bubble_sort(arr,n);
	for(int i=0;i<n;i++){
		if(arr1[i]==arr[0]){x=i;}
	}
	return x;
} 
void string_sort(char *A,int n){
	for(int i=n; i>1;i--){
		int maxindex = max(A,i);
		char temp[]="A[maxindex]";
		A[maxindex]=A[i-1];
		A[i-1]=temp;
	}
}
main_program{
	int n;
	cin>>n;
	char A[n][12]; 
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	string_sort(A,n);
	for(int i=0;i<n;i++){
		cout<<A[i]<<endl;
	}
	cout<<(n*n-n)/2;
	
	
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
#define MAX 11
void swap( int &a, int &b)
{
	int temp= a;
	a=b;
	b=temp;
}
int string_compare(char first[], char second[])
{
	int i=0;
	while(true)
	{
		if (first[i] == 0 && second[i] == 0) return 0;
	if (first[i] == 0) return -1;
	if (second[i] == 0) return +1;
	if (first[i] < second[i]) return -1;
	if (first[i] > second[i]) return +1;
	else if(first[i]==second[i])
	i++;
	}

}
int determination(char s[][MAX], int n, int &ctr1)
{
	int indi; int index=0;
	for(int i=0; i<n-1;i++)
	{
		
	indi= string_compare(s[i],s[i+1]);
	ctr1++;
	if(indi==1)
		index++;
	}
	return index;
}
void string_sort( char s[][MAX], int n,int &ctr1,int &ctr2)
{ 
	for(int i=n-1;i>0;i--)
	{
		int index= determination(s,n,ctr1);// minimum index
		if(index!=i)
		{
			swap(s[index],s[i]);
			ctr2++;
		}
	}
}
int main()
{	
	int n; int ctr1=0;//number of times compare is called
	int ctr2=0;// the number of times swapped
	cin>>n;
	char s[n][MAX];
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	string_sort(s,n,ctr1,ctr2);
	for(int i=0;i<n;i++)
	{
		cout<<s[i]<<endl;
	}
	cout<<ctr1<<endl<<ctr2;
	//number of times compare was called then  swap times
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>

using namespace std;
void input(int n,char arr[][12]){

for(int i=0;i<n;i++){

cin>>arr[i][12];

}
}

int main() {

int n;cin>>n;
char arr[n][12];

input(n,arr);

for(int i=0;i<n;i++){

cout<<arr[i][12];
}


}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: D
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include <iostream>
using namespace std;
void copy(char *s, char *t)
{
	while (*s++ = *t++); 
}
void swap(char *s,char *t)
{
	char *temp;
	copy(temp,s);
	copy(s,t);
	copy(t,temp);
}
int string_compare (char first[], char second[])
{
	int i = 0;
	while (true)
	{
	if (first[i] == 0 && second[i] == 0) return 0;
	if (first[i] == 0) return -1;
	if (second[i] == 0) return +1;
	if (first[i] < second[i]) return -1;
	if (first[i] > second[i]) return +1;
	i++;
	}
}
int s1(char str[][], int l)
{
	int m=0;
	for(int j=1;j<l;j++)
	{
		if(string_compare(str[m],str[j]== 1){m=j;break;}
	}
	return m;
}
void sort(char str[][],int n)
{
	for(int i=n; i>1;i--)	
	{
		int m=s1(str,i);
		swap(&str[m],&str[i-1]);
	}
}
int main()
{
	int n;
	cin>>n;
	char string_2d[11][n];
	for(int i=0;i<n;i++)
	{
		cin>>string_2d[i];
	}
	sort(string_2d,n);
}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the selection-sort algorithm.

Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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


int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return -1;
if (second[i] == 0) return +1;
if (first[i] < second[i]) return -1;
if (first[i] > second[i]) return +1;
i++;
}}
void swap (char *a, char *b)
{
    float temp;
    temp = *a;
    *a = *b;
    *b = temp;
    
}

int argmax(char *marks, int L)
{
	int maxindex = 0;
	for(int j=1; j<L; j++){
		// update the index if a larger element is found
		if(marks[maxindex] < marks[j]) maxindex = j;
	}
	return maxindex;
}


void selection_sort (char *data, int n,int* acomp,int* aswp)
{
    for(int i=n; i>1;i--)
    {  
        int maxindex = argmax(data,i);
        *acomp=(i-1)+*acomp;
        // get the maximum of the first i elements
        if(aswp>=0)
        {swap(&data[maxindex],&data[i-1]); *aswp= *aswp+1;}
        
         // refer to earlier slides for this!
        // at this point, data[i-1] will be in the correct position for a sorted array
    }
}

int main()
{
  int n,comp=0,swp=0;
 
  
  cin>>n;
  char arr[n][11];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  selection_sort(arr[11],n,&comp,&swp);
  
  for(int i =n-1;; )
  {if(i<0)break;
    cout<<arr[i]<<endl;
    i--;
    
  }
  cout<<comp<<endl;
  cout<<swp<<endl;
  
  
  

}

Grading criterion: Sorting algorithm implemented is selection sort.
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction. (eg different sorting algo)
Rating D: Code not there or totally wrong
Assigned grade: C