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;
#define MAX 100
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 argmax (char A[][MAX], int L){
	int i;
	int j=0;
	for(i=1;i<L;i++){
	    	int m = string_compare(&A[j],&A[i])
	    	if (m == -1) ;
	    	if(m==1) j=i;
	    	else ;
	}
	return j;
}
void string_sort(char A[][MAX]){

	for(int i=n; i>1;i--){
		int maxindex = argmax(s,i);
		myswap(&A[maxindex],&A[i-1]);
	}
}
int main(){
	int n;
	cin>>n;
	char A[n][MAX];
int count=0;
while (cin.getline(A[count++], 11)); // terminated by ctrl-Z
	string_sort(A);
	for(int i=0;i<n;i++){
		int m;
		for(int j=0;j<12;j++){
			if(A[i][j]='\0') m=j;
		}
		for(m-1;m<=0;m--){
	 	cout<<A[i][m];
		}
		cout<<"\n";
}
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
Assigned grade: A
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>
#include<cstring>
using namespace std;

int compare_function(char a[],char b[])
{
int i=0,j=0;
while(a[i] || b[j])
{
	if(a[i]==b[j])
	continue;
	else if(a[i]>b[j])
	{
	return -1;
	break;
	}
	else
	{
	return 1;
	break;
	}
	i++;j++;
}
if(i==j)
return 0;
}

void string_sort(char a[][100],int n)
{
	int i,j,k;
	char temp;
	for(k=0;k<n;k++)
	{
	for(i=0;i<strlen(a[k])-1;i++)
	{
	for(j=i+1;j<=strlen(a[k]);j++)
	{
	if(a[i]<a[j])
	{
	temp=a[k][i];
	a[k][i]=a[k][j];
	a[k][j]=temp;
	}
	}
	}
	cout << a[k];
	}
	cout << k;
 }
int main()
{
	char a[100][100];
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
	cin >> a[i];
	string_sort();
	string_compare();

}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
Assigned grade: A
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 *A,char *B){
	int i=0;
	while(true){
		if(A[i]==0 && B[i]==0){cout<<i+1;return 0;}
		if(A[i]==0){cout<<i+1;return -1;}
		if(B[i]==0){cout<<i+1;return +1;}
		if(A[i]>B[i]){cout<<i+1;return -1;}
		if(A[i]<B[i]){cout<<i+1;return +1;}
		i++;
	}
	cout<<i+1;return 0;
}
void swap(char &a,char&b){char temp=a;a=b;b=temp;return;}
void string_sort(char A[][12],int n){
	int sw=0;
		for(int k=0;k<n;k++){
			if(string_compare(A[k][12],A[k+1][12])==-1){
				sw=sw+1;swap(A[k][12],A[k+1][12]);
			}
		}
	char B[n][12];
	for(int m=0;m<n;m++){B[n-1-m][12]=A[m][12];}
	for(int h=0;h<n;h++){cout<<B[h][12]<<endl;}
	cout<<n<<endl<<sw;return;}
int main(){
	int n,m;cin>>n;char A[n][12];int i,j;
for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>A[i][j]; 
	string_sort(A[n][12],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>
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*string, int m){
int maxindex=0;
for (int i=1; i<m; i++){
if(string[maxindex]<string[i]) maxindex=i;
}
for(j=1; j<m; j--){
swap( string[maxindex], string[j-1]);
}
int main(){
int n;
cin>>n;
int A[n][MAX];
cin.getline(n,MAX);
}




























int main(){

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 main()
{
int n,i;
int array[n];
cin>>array[n];
for(i=0;i<n;i++){
int string_sort(n);
cin>>n;
}
cout<<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 11
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;
}
int minindex(char s[][Max],int n){
 		for(int i=0;i<n;i++){
 			for(int j=0;j<Max;j++){
 				char a[n];
 				a[i]=s[i][j];
 			}
 		}
 				for(int k=0;k<n;k++){
 					int cnt=string_compare()
 				}
 			}
 		}
}
 		}
}

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 *A,char *B){
int i=0;
while(true){
if(A[i]==0) && B[i]==0)return 0;
if(A[i]==0)return 1;
if(A[i]<B[i]) return 1;
if(A[i]>B[i]) return -1;
i++;
}
return 0;
}
int inputStrings(char **A,int n){
int numString=0;
for(int j=1;j<n;j++){
int k=string_compare(a[numString],a[j]);
if(k==1) numString=j;}
return numString;
}
void myswap(char *&A,char *&B){
char *temp=A;
A=B;
B=temp;
}
void string_sort(char *&A,int n){
for(int i=n;i>0;i--){
int numString=inputString(A,n);
myswap(a[numString],A[i-1]);
}}

int main(){
int n;
cin>>n;
char *A=new char [n];
for(int i=0;i<n;i++){
A[i]=new char[10]; }

for(int i=0;i<n;i++){
cin.getline(A[numString],10);
}
int res=string_compare(A,B);
cout<<res;
int d=inputstring(*A,n);
cout<<d;
string_sort(A,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: 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<iostream>
using namespace std;

void input(char arr[][12], int n){
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

}

void print(char arr[][12], int n){
	for(int i = 0; i < n; i++){
		cout << arr[i] << endl;
	}
}



int string_length(char str[]){
	int l = 0;

	while(str[l] != 0) l++;

	return l;
}

int string_compare(char str1[], char str2[]){
	int n1 = string_length(str1), n2 = string_length(str2); 
	int n = min(n1,n2);
	for(int i = 0; i < n; i++){
		if(str1[i] < str2[i])
			return 1;
		else if(str1[i] > str2[i])
			return -1;
		else 
			continue;
	}
	if(n1 < n2)
		return 1;
	else if(n1 > n2)
		return -1;
	else 
		return 0;
}

void string_copy(char str1[], char str2[]){
	for(int i = 0; i < 12; i++){
		str2[i] = str1[i];
	}
}

void string_swap(char arr[][12], int a, int b){
	char temp[12];
	string_copy(arr[a],	temp	);
	string_copy(arr[b],	arr[a]	);
	string_copy(temp,	arr[b]	);
}

void string_sort(char arr[][12], int n,  int &stringCompares, int &stringSwaps){

	int index_of_largest_str;

	for(int i = 1; i < n; i++){
		index_of_largest_str = i -1;
		for(int j = i; j < n; j++){
			if( string_compare(arr[index_of_largest_str], arr[j]) == 1){
				index_of_largest_str = j;
				
			}
			stringCompares++;
		}
		if(index_of_largest_str != i-1){
			string_swap(arr, index_of_largest_str, i-1);
			stringSwaps++;
		}
	}
}



int main(){
	int n;
	cin >> n;

	
	char arr[n][12];

	input(arr, n);

	int stringCompares = 0, stringSwaps = 0;
 	string_sort(arr,n, stringCompares, stringSwaps);

	print(arr,n);

	cout << stringCompares << endl << stringSwaps << 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: A
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 argmax (float *scores, int L){
	int maxindex = 0;
	for(int j=1; j<L; j++){
		if(scores[maxindex] < scores[j]) maxindex = j;	
	}
	return maxindex;
}
void selection_sort (float *data, int n){
for(int i=n; i>1;i--){
int maxindex = argmax(data,i); 
myswap(&data[maxind}
ex],&data[i-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 main(){ 
	int n;
	cin>>n;
char name[n][11];
int count=0;
while (cin.getline(name[count++], 11));
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << name[i] << "]" << 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
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 *a,char *b)
{
int i=0;
	while(true)
{
	if(a[i]==0 && b[i]==0) return 0;
	if(a[i]==0) return -1;
	if(a[i]==0) return -1;

	if(a[i]<b[i]) return -1;
	f(a[i]>b[i]) return 1;
	i++;
	}
return 0;
}




main_program{
int n;
cin>>n;

char a[12][12];
char b[12][12];

	cin.getline(a,n);
	
	cin.getline(b,n);
	
	
	string_compare(a,b);
	
}

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 *a, char *b){
int i = 0;
while (true){
if (a[i] == 0 && b[i] == 0) return 0;
if (a[i] == 0) return 1;
if (b[i] == 0) return -1;
if (a[i] < b[i]) return 1;
if (a[i] > b[i]) return -1;
i++;
}
return 0;
}
int fmin( char **a,int n,int &c){
int minindex = 0;
for(int j=1; j<n; j++){
int k=string_compare(a[minindex],a[j]);	
if(k==-1) minindex = j;
c++;	
}
return minindex;
}
void myswap(char* &a,char* &b){
char *temp=a;
a=b;
b=temp;
} 
void string_sort (char **&a, int n,int &c,int &s){
for(int i=n; i>1;i--){
int minindex = fmin(a,i,c); 
if(a[minindex]!=a[i-1]) s++;
myswap(a[minindex],a[i-1]);
}
}
int main(){
int n,c=0,s=0;
cin>>n;
char **a=new char*[n];
for(int i=0; i<n; i++) a[i]=new char[12];
for(int i=0; i<n; i++) cin>>a[i];
string_sort(a,n,c,s);
for(int i=0; i<n; i++) cout<<a[i]<<endl;
cout<<c<<endl<<s;
}

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: A