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>
using namespace std;
const int MAX=12;
void myswap (char a[][MAX], int &g, int j)
{g++; int k =0, l=0,m=0;
 char temp [MAX];
	for (int i=0; a[j][i]!=0; i++)
	{
		temp[i]=a[j][i];
		k++;
	}
 temp [k]=0;
 for (int i=0; a[j-1][i]!=0; i++)
	{
		a[j][i]=a[j-1][i];
	 l++;
	}
 a[j][l]=0;
 for (int i=0; temp[i]!=0; i++)
	{
		a[j-1][i]=temp[i];
	 m++;
	}
 a[j-1][m]=0;
}

int string_compare (char a[][MAX], int i, int &f)
{f++;
	for (int j=0; j<12; j++)
	{
		if (a[i][j]<a[i+1][j]) return 1;
		if (a[i][j]>a[i+1][j]) return -1;
		if (a[i][j]==0) return 1;
		if (a[i+1][j]==0) return -1;
		else return 0;
	}
}

void string_sort (char a[][MAX], int n, int&f, int&g)
{
	int i,j;
	for (i=1;i<n;i++)
	{
		j=i;
		while (j>0 && string_compare(a,j-1,f)==-1)
		{
			myswap (a,g,j);
			j--;
		}
	}
}

int main ()
{
	int g=0, f=0;
	int n;
	cin >> n;
	char a[n][MAX];
	for (int i=0; i<n; i++)
	{
		cin >> a[i];
	}
	string_sort(a,n,f,g);
	for (int i=n-1; i>=0; i--)
	{
		cout << a[i] << endl;
	}
	cout << f << endl;
	cout <<g;
}

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;
#define MAX 20
int stringlength(char* s)
{int i = 0,num = 0;
	while(s[i] != 0)
	{i++;num++;}
	return num;
}
void stringswap(char* s,char* t)
	{
		char temp[15];
		int a = stringlength(s);
		int b = stringlength(t);
		for(int i = 0;i < a;i++)
		{temp[i] = s[i];}
		for(int i = 0;i < a;i++)
			s[i] = 0;
		for(int i = 0;i < b;i++)
		{s[i] = t[i];}
		for(int i = 0;i < b;i++)
			t[i] = 0;
		for(int i = 0;i<a;i++)
		{t[i] = temp[i];}
	}
int string_compare(char* s,char* t)
	{
		int i = 0;
		while(true)
			{
				if(s[i] == 0 && t[i] == 0) return 0;
				else if(s[i] == 0) return 1;
				else if(t[i] == 0) return -1;
				else if(s[i] > t[i]) return -1;
				else if(s[i] < t[i]) return 1;
			}
	return 0;
	}
void string_sort(char A[][MAX],int n,int num1,int num2)
	{
		int i,j;
		for(i = 1;i < n;i--)
			{
				j = i;
				num2++;
			while(j > 0 && string_compare(A[j],A[j-1]) == 1)
				{
					stringswap(A[j],A[j-1]);
					num1++;
					j--;
				}
				
			}
	}
	
int main()	{
		int n;
		cin >> n;
		char a[MAX][MAX];
		for(int i = 0;i < n;i++)
			{
				cin.getline(a[i],MAX);
			}
		int num1 = 0,num2 = 0;
		string_sort(a,n,num1,num2);
		for(int i = n-1;i >=0;i--)
		{
			cout << a[i] << endl;
		}
		cout << n << endl << num1;
		
	
	}

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 100
using namespace std;
void swap(char *a,char *b){
char t=*a;
*a=*b;
*b=t;
}
int string_compare(char *f,char *s){
int i=0;
while(true){
if(f[i]==0 && s[i]==0) return 0;
else if(f[i]==0) return 1;
else if(s[i]==0) return -1;
else if(f[i]<s[i]) return 1;
else if(s[i]<f[i]) return -1;
i++;
}
return 0;
}
void string_sort(char *A,int n){
for(int i=0;i<n;i++){
 for(int j=i+1;j<n;j++){
  if(A[j]>A[i]){swap(&A[j],&A[i]);}
for(int p=0;p<n;p++){cout<<A[p]<<" ";}
cout<<endl;

}
}
}
int main(){
int n;
cin>>n;
char  A[n];
for(int i=0;i<n;i++){
cin.sync();
cin>>A[i];}
string_sort(A,n);
cout<<endl;
cout<<n<<2;}

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;
#define MAX 100
/*int strlen(char *s){
int i = 0;
while (s[i] != '\0') i++;
return i;
}*/
int x=0;
int c=0;
int string_compare (char *A, char *B){
int i = 0;
x++;
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;
}

void mswap(char **S,int n1,int n2){
	char* c = new char;
	int i;
	for(i=0;S[n1][i]!= '\0';i++){
		c[i] = S[n1][i];
	}
	c[i] = S[n1][i];

	int j;
	for(j=0;S[n2][j]!= '\0';j++){
		S[n1][j] = S[n2][j];
	}
	S[n1][j] = S[n2][j];

	int k;
	for(k=0;c[k]!= '\0';k++){
		S[n2][k] = c[k];
	}
	S[n2][k] = c[k];
}

void string_sort(char **S,int n){
int i,j;
for (i=2;i<n+1;i++){ 
j = i;
while (j > 1 && string_compare(S[j-1],S[j])==-1) {
mswap(S,j,j-1);
c++;
j = j - 1;
}
}
}

int main(){
int n;
cin >>n;
char **S=new char* [n+1];
for(int i=0;i<n+1;i++){
	S[i]=new char;
	cin.getline(S[i],12);
}
string_sort(S,n);
for(int i=1;i<=n;i++){
cout << S[i] << endl;}
cout << x << endl << c;
}

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;
#define Max 12

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;
}
void insertion_sort (char A[][Max], int n, int &p,int &q) {
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;p=p+j;
        while (j > 0 && string_compare(A[j-1],A[j])==-1) {
        char* temp;
            for(int k=0;k<12;k++){temp[k] =A[j][k];}
            for(int k=0;k<12;k++){A[j][k]=A[j-1][k];}
            for(int k=0;k<12;k++){A[j-1][k]= temp[k];}
                
            q++;
            j=j-1;
        }
    }
}

int main(){
    int n,p=0,q=0;
    cin>>n;
    char a[n][12];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    insertion_sort(a,n,p,q);
    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }
    cout<<p<<endl<<q;
}

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<cmath>
using namespace std;
#define max 100
int string_compare (char* f, char* s){
int i = 0;
while (true){
if (f[i] == 0 && s[i] == 0) return 0;
if (f[i] == 0) return 1;
if (s[i] == 0) return -1;
if (f[i] < s[i]) return 1;
if (f[i] > s[i]) return -1;
i++;
}
return 0;
}
void string_sort(char a[][max],int n){
int h=0,x=0;
for(int i=1;i<n;i++){
for(int j=i;j>0;j--){
int p=string_compare(a[j-1],a[j]);h++;
if(p==1){
swap(a[j-1],a[j]);x++;
}
}
}
for(int i=0;i<n;i++){cout<<a[i]<<endl;}
cout<<h<<endl;
cout<<x;
}

int main(){
int n;cin>>n;
char a[max][max];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
string_sort(a,n);
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 string_compare(char *a,char *b){
	int track = 0;
	while(track<11){
		if(a[track]>b[track]){
			return -1;
			break;
		}
		else if(a[track]<b[track]){
			return 1;
			break;
		}
		else if(a[track]==b[track]){
			track++;
		}
	}
	return 0;
}

void string_swap(char *a,char *b){
	char temp[12];
	for(int i = 0;i<12;i++){
		temp[i] = a[i];
	}
	for(int i = 0;i<12;i++){
		a[i] = b[i];
	}
	for(int i = 0;i<12;i++){
		b[i] = temp[i];
	}
}

void string_sort(char a[][12],int n){
	int i,j,cC = 0,sC = 0;
	for(int i = 1;i<n;i++){
		j = i;
		int val = string_compare(a[j-1],a[j]);
		cC++;
		while(j>0&&val==1){
			string_swap(a[j-1],a[j]);
			sC++;
			j = j-1;
			val = string_compare(a[j-1],a[j]);
			cC++;
		}
	}
	for(int i = 0;i<n;i++){
		cout<<a[i]<<endl;
	}
	cout<<cC<<endl;
	cout<<sC;
}

int main(){
	int n;
	cin>>n;
	char wordlist[n][12];
	for(int i = 0;i<n;i++){
		cin>>wordlist[i];
	}
	string_sort(wordlist,n);
	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;
#define max 100
char ng_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 myswap(char* a, char* b)
{       
char temp[max];
int i;
for(i=0;a[i]!='\0';i++){
	temp[i]=a[i];

}
temp[i]=a[i];

for(i=0;b[i]!='\0';i++){
	a[i]=b[i];
}
a[i]=b[i];

for(i=0;temp[i]!='\0';i++){
	b[i]=temp[i];
}
b[i]=temp[i];





}


void insertion_sort (char*A,int n){
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        int l=ng_compare(*A[j],*A[j-1]);
        while (j > 0 && l==-1){}
	 
          myswap(A[j],A[j-1]);
            j = j - 1;
        }
    }

int main()
{
int n;
cin>>n;
char a[n][max];
for(int i=0;i<n;i++)
cin>>a[i];
insertion_sort(a,n);
for(int i=n;i>0;i--)
cout<<a[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: 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 string_compare(char* first,char* second,int& x){
int i=0;
x++;
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[][11],int n,int& x,int& y){
int i,j;
x=0;
y=0;
for(i=1;i<n;i++){
j=i;
while(j>0 && string_compare(A[j-1],A[j],x)==-1){
swap(A[j],A[j-1]);
y++;
j=j-1;
}}}
int main(){
int n,x,y;
cin>>n;
char A[n][11];
for(int j=0;j<n;j++){
cin>>A[j];}
string_sort(A,n,x,y);
for(int i=0;i<n;i++){
cout<<A[i]<<endl;}
cout<<x<<endl;
cout<<y;
}

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