CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#include<cstring>
#include<cmath>
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 swapt(char *a, char *b){
char tempt[100];
for(int i=0; i<15; i++)
{
tempt[i]=a[i];
a[i]=b[i];
b[i]=tempt[i];
}}

void string_sort (char A[][12], int n) {
    int i, j,c;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && A[j-1] < A[j]){
            swapt(&A[j],&A[j-1]);c++;
            j = j - 1;
        }
    }
}

int main(){
int n;
cin>>n;
//char a[n][12];
//for(int i=0;i<n;i++)
//{
//cin>>a[i];
//}
//char b[n][12]=string_sort(a,n);
//cout<<b[n][12];
//}
char name[n][12];
int count=0;
cout << "Enter at most 5 names with at most 19 characters each:\n";
while (cin.getline(name[count++], 20)); // terminated by ctrl-Z
cout << "The names are:\n";
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << name[i] << "]" << endl;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

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

void swap(char*&a,char*&b){
	char t[max];
	int i=0;
	while(a[i]!='\0'){
		t[i]=a[i];i++;}
	t[i]='\0';
	i=0;
	while(b[i]!='0'){
		a[i]=b[i];i++;}
	a[i]='\0';
	i=0;
	while(t[i]!='\0'){
		b[i]=t[i];i++;}
	b[i]='\0';
	}

int string_compare(char *a,char*b){
	int i=0;
	while(true){
		if(a[i]=='\0' && b[i]=='\0') return 0;
		else if(a[i]=='\0') return -1;
		else if(b[i]=='\0') return 1;
		else if(a[i]>b[i]) return 1;
		else if(a[i]<b[i]) return -1;
		i++;}
	}

int string_sort(char a[][max],int n,int *noc){
	int count=0;
	for(int i=0;i<n;i++){
		bool flag=false;
		if(i==0) continue;
		else{
			int j=i;
			int gf=string_compare(a[j],a[j-1]);*noc+=1;
			while(string_compare(a[j],a[j-1])==1){
				swap(a[j],a[j-1]);count++;
				j--;flag=true;
				*noc+=1;
				if(j==0)break;}}
		if (flag==false)break;}
	return count;}

int main(){
	int n,noc=0;
	cin>>n;
	char words[n][max];
	for(int i=0;i<n;i++){
		cin>>words[i];}
	int h=string_sort(words,n,&noc);
	for(int i=0;i<n;i++){
		cout<<words[i]<<'\n';}
	cout<<noc<<"\n"<<h;}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#define MAX 50
using namespace std;
void string_swap(char A[], char B[]){
	char temp[MAX];
	int i, j, k;
	for(i=0; A[i]!=0; i++)
	{
		temp[i]=A[i];
	}
	temp[i]=0;
	for(j=0; B[j]!=0; j++)
	{
		A[j]=B[j];
	}
	A[j]=0;
	for(k=0; temp[k]!=0; k++)
	{
		B[k]=temp[k];
	}
	B[k]=0;
}
int string_compare(char A[], char B[]){
	int i=0;
	while(true)
	{
		if(A[i]==0 && B[i]==0){return 0;}
		else if(A[i]==0) {return 1;}
		else if(B[i]==0){return -1;}
		else if(A[i]>B[i]){return -1;}
		else if(B[i]>A[i]){return 1;}
		i++;
	}
}
void string_sort(char A[MAX][MAX], int n, int &a, int &b){
	int i,j;
	int cnt_cmp, cnt_swap;
	cnt_cmp=cnt_swap=0;
	for(i=1; i<n; i++)
	{
		j=i;
		cnt_cmp++;
		while(j>0 && (string_compare(A[j],A[j-1])==1))
		{
			string_swap(A[j],A[j-1]);
			j--;
			cnt_swap++;
			if(j!=0){cnt_cmp++;}
		}
	}
	a=cnt_cmp;
	b=cnt_swap;
}
int main(){
	int n, cnt_cmp, cnt_swap;
	cin >> n;
	char A[MAX][MAX];
	for(int i=0; i<n; i++)
	{
		cin>>A[i];
	}
	string_sort(A,n,cnt_cmp,cnt_swap);
	for(int j=n-1; j>=0; j--)
	{
		cout << A[j] << endl;
	}
	cout << cnt_cmp << endl;
	cout << cnt_swap;
	return 0;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;
int c_comp=0;
int c_swap=0;
int string_compare(char*a, char*b)
{
	c_comp++;
	int i=0;
	while (i<11)
	{
		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;
}
void copy(char*dest, char*source) 
{
	int i;
	for(i=0;source[i]!='\0';i++)
	{
		dest[i]=source[i];
	}
	dest[i]=source[i];
}
void swap(char*a, char*b)
{
	char c[11];
	copy(c,a);
	copy(a,b);
	copy(b,c);
	c_swap++;
}
void string_sort(char A[][11],int n)
{
	int i, j;
    for (i=1;i<n+1;i++)
    {
        j = i;
        while (j > 0 && string_compare(A[j],A[j-1])==1) 
        { 
	        swap (A[j],A[j-1]);
            j--;
        }
    }
}
int main()
{
	int n;
	cin>>n;
	char A[n][11];
	for (int i=0;i<n+1;i++)
	{
		cin.getline(A[i],11);
	}
	string_sort(A,n);
	for (int u=0;u<n+1;u++)
	{
		for (int v=0;A[u][v]!='\0';v++)
		{
			cout<<A[u][v];
		}
		cout<<endl;
	}
	cout<<c_comp<<endl<<c_swap;
	
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#include<cstring>
#define MAX 11
#define MAX2 1

int string_compare (char *first, char * second,count){
int i = 0;
count = count + 1;
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 eqarr(char A[MAX2][MAX],char* string,int j,int n){
	for(int i = 0;i < n;i++){
		A[j][i] = string[i];
	}
}

void insertion_sort (char A[MAX2][MAX], int n) {
    int i, j;
    int co = 0;
    int count = 0;
    for (i=1;i < n;i++){ // for each element of the array
        j = i;
        while (j > 0 && (string_compare(A[j - 1],A[j],count) == -1)) { // find the location to insert it to
	 // maintain a sorted subarray of i elements
            char c[MAX];
            for(int k =0;k < n;k++){
            	c[k] = A[j-1][k];
            }
            
            eqarr(A,A[j],j-1,n);
            eqarr(A,c,j,n);
            co = co + 1;
            j = j - 1;
        }
    }
}

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

	}
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: B
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<simplecpp>
#define MAX 100

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

void string_sort(char charr[][MAX], int n, int& n1, int& n2){
	for(int i=1; i<n; i++){
		int j=i;
		while(j>0 && string_compare(charr[j-1], charr[j], n1)==-1){
			for(int k=0; k<MAX; k++){
				swap(charr[j-1][k], charr[j][k]);
			}
			n2++;
			j--;
		}
	}
}

main_program{
	int n, n1=0, n2=0;
	cin>>n;
	char charr[MAX][MAX];
	for(int i=0; i<n; i++){
		cin>>charr[i];
	}
	string_sort(charr, n, n1, n2);
	for(int i=n-1; i>=0; i--){
                cout<<charr[i]<<endl;
        }
	cout<<n1<<endl<<n2<<endl;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

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

int comp_c=0,swap_c=0;

void sw(int a,int b,char s[][MAX]){
swap_c++;
char dum[12];

for(int i=0;i<12;i++){
    dum[i]=s[a][i];
}

for(int i=0;i<12;i++){
    s[a][i]=s[b][i];
}

for(int i=0;i<12;i++){
    s[b][i]= dum[i];
}

}


int cs(int a,int b,char s[][MAX]){
comp_c++;
int i=0;

while(true){

if(s[a][i] == '\0' && s[b][i] == '\0')return 0;
if(s[a][i] == '\0')return 1;
if(s[b][i] == '\0')return -1;
if(s[a][i] > s[b][i])return -1;
if(s[a][i] < s[b][i])return 1;
i++;

}
return 0;

}

void ss(char s[][MAX],int n){

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

for(int i=1;i<n;i++){
    for(int j=i;j>0;j--){
        if( cs(j-1,j,s)!= -1 )break;
        sw(j-1,j,s);
    }
}

}

int main(){

int n;cin>>n;

char s[n][MAX];

ss(s,n);

for(int i=n-1;i>=0;i--){
    cout<<s[i]<<endl;
}
cout<<comp_c<<endl<<swap_c<<endl;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

Problem Description: 
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:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. 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. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

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

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

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

int compare=0,swaps=0;

void swap(string *a,string *b){
   string *temp;
   *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) {compare++; return 0;}
if (first[i] == 0) {compare++;return -1;}
if (second[i] == 0) {compare++; return +1;}
if (first[i] < second[i]) {compare++;  return -1;}
if (first[i] > second[i]) {compare++; return +1;}  }
return 0; }

void string_sort(int n,char str[][12]){
     int i,j;
  if(n<15){
     for(int i=n-1;i>0;i--){
        j=i;
       while(j>0 && string_compare(str[j],str[j-1])<0){
            swap(str[j],str[j-1]);
             j-- ; swaps++; } }} }

int main(){
   int n; cin>>n;
   char str[100][12];
   for(int i=0;i<n;i++){
     cin>>str[i];}
    string_sort(n,str);
if(n<15){
  for(int i=n-1;i>=0;i--){
    cout<<str[i]<<endl; }
  cout<<compare<<endl<<swaps;
     }  }

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C