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>
#define MAX 100
using namespace std;
int strComp=0, strSwap=0;
void print(char a[][MAX], int n)
{
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<endl;
	}
}
void string_swap(char a[], char b[])
{
	char temp[MAX]; int i=0,j=0,k=0;
	while(a[i]!=0){temp[i]=a[i]; i++;}
	temp[i]=0;
	while(b[j]!=0){a[j]=b[j]; j++;}
	a[j]=0;
	while(temp[k]!=0){b[k]=temp[k]; k++;}
	b[k]=0;
}
int string_compare(char a[], char b[])   //first before second = 1
{
	int i=0; strComp++;
	while(1)
	{
		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(b[i]>a[i]) return 1;
		if(a[i]=b[i]) i++;
	}
}
void string_sort(char a[][MAX], int n)
{
	int i,j;
	for(int i=0;i<n;i++)
	{

		j=i;

		while(j>0)
		{
			if(string_compare(a[j-1],a[j])==1)
			{
				string_swap(a[j-1],a[j]);
				strSwap++;
			}
			j--;
		}
	}
}

int main()
{
	int n;
	cin>>n;
	char parent [MAX][MAX];
	for(int i=0;i<n;i++)
	{
		cin>>parent[i];
	}
	string_sort(parent,n);
	print(parent,n);
	cout<<strComp<<endl<<strSwap;
	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: 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 <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 string_copy (char *dest, const char* source) {
	int i;
	for(i=0;source[i]!= 0;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}

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


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

}

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;
#include <cstring>
int count =0,hue=0;
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_copy (char *dest,  char* source) {
	int i;
	for(i=0;source[i]!= 0;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}
void string_sort (char **a,int n){
	int j=1;
    for (int i=1;i < n;i++){ 
        j = i;
        while (j > 0 && string_compare(a[j-1],a[j])==1 ) { 
            char temp[12];string_copy(temp,a[j]);
			string_copy(a[j],a[j-1]);
			string_copy(a[j-1],temp);
            j = j - 1;count++;hue++;
        }
	if(j!=0) count++;
    }
	
}

int main(){
	int n;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);
	for(int i=n-1;i>=0;i--){
		cout<<a[i]<<endl;
	}cout<<count<<endl<<hue;
	
	
	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>
#include<cstring>
using namespace std;
void swap(int *a,int *b){
        int temp=*a;
        *a=*b;
        *b=temp;
}
int string_compare (char *A, char *B){
int i = 0;
while (true){
if (A[i] < B[i]) return -1;
if (A[i] > B[i]) return +1;
        else return 0;
i++;
}
return 0;
}
int numswap=0;
int numcomp=0;
void insertion_sort (char *A, int n) {
    int i, j;
    for (i=1;i < n;i++){ 
                numcomp++;
        j = i;
        while (j > 0 && string_compare(A[j-1] ,A[j])==1){ 
            swap(&A[j],&A[j-1]);
            j = j - 1;
                        numswap++;
        }
    }
}

int main(){
        char *A;
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
                cin>>A[i];}
        insertion_sort(A,n);
        for(int j=0;j<n;j++){
                cout<<A[j];}
        cout<<numcomp<<" "<<numswap;
}

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 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++;
}
}

void string_sort(char arr[][MAX], int n, int* ctrswap, int* ctrcmp)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
int cmp=string_compare(arr[j],arr[j+1]);
ctrcmp++;
if(cmp==-1)
{
char a[MAX];
strcpy(a,arr[j]);
strcpy(arr[j],arr[j+1]);
strcpy(arr[j+1],a);
ctrswap++;}
}
}
}

int main()
{
int n,ctrswap=0,ctrcmp=0;
cin>>n;
char arr[n][MAX];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
string_sort(arr,n,&ctrswap,&ctrcmp);
for(int i=n-1;i>=0;i--)
{cout<<arr[i]<<endl;}
cout<<ctrcmp<<endl;
cout<<ctrswap;
}

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>
#include<string.h>
using namespace std;

#define max 12

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

void string_sort(char a[][max],int n,int &x,int &y)
{
int i,j;
for(int i=1;i<n;i++)
  {
  j=i;
  while(j>0 && string_compare(a[j-1],a[j],x)==-1)
          {
          swap(a[j-1],a[j]);
          j=j-1;  y=y+1;
          }
  }
}

int main()
{
int n;
cin>>n;
char a[n][max];
for(int i=0;i<n;i++) cin>>a[i];
int x,y;
x=y=0;
string_sort(a,n,x,y);
for(int i=n-1;i>=0;i--) cout<<a[i]<<endl;
cout<<x<<endl<<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
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 w[][15],int j){
int a,b,n1,n2;n1=n2=a=b=0;
while(w[j][a]!='\0')a++;
while(w[j+1][b]!='\0')b++;
while(n1<a && n2<b){
if(w[j][n1]>w[j+1][n2])return -1;
else if(w[j][n1]<w[j+1][n2]) return 1;
else if(w[j][n1]==w[j+1][n2]){n1++;n2++;}
if(n1==a&& n2==b)return 0;
else if (n1==a) return 1;
else if(n2==b) return -1;
}
}
void myswap(char w[][15],int j){
int a,b;a=b=0;
while(w[j][a]!='\0')a++;
while(w[j+1][b]!='\0')b++;
char temp[a];
for(int i=0;i<=a;i++)temp[i]=w[j][i];
for(int i=0;i<=b;i++)w[j][i]=w[j+1][i];
for(int i=0;i<=a;i++)w[j+1][i]=temp[i];
}
void string_sort(char w[][15],int n){
int swap,compare;
swap=compare=0;
for(int i=1;i<n;i++){
for(int j=i-1;j>=0;j--){
 int k=string_compare(w,j);compare++;//compares w[j],w[j+1]
  if(k==1){myswap(w,j);swap++;}//swaps w[j] ,w[j+1]:
  else  break;
  }
 }
for(int i=0;i<n;i++){cout<<w[i]<<endl;}
cout<<compare<<endl<<swap;
}
int main(){
int n;cin>>n;
char w[n][15];
for(int i=0;i<n;i++){cin>>w[i];}
string_sort(w,n);
}

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 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 string_sort(char a[][11],int n){
int i,j;
	for(i=1;i<n;i++){
         j=i;
	while(j>0 && string_compare(a[j-1],a[j])==+1){
	for(int k=0;k<11;k++){
        swap (a[j-1][k],a[j][k]);
	j=j-1;
	}
      }
   }
}
int main(){
int n;
int count=0;
cin>>n;
char arr[n][11];
while(cin.getline(arr[count++],12));
string_sort(arr,n);
for(int i=0;i<n;i++){
	cout<<arr[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>
using namespace std;
int string_compare(char* a, char* b, int& A){
A++;
int i=0;
for(; ;i++){
if(a[i]==0 && b[i]==0) {return 0;}
else if(a[i]>b[i] || b[i]==0) {return -1;}
else if(a[i]<b[i] || a[i]==0) {return 1;}}}

void swaap(int& B,char* a, char* b){
int temp[12];B++;
int i=0,j=0,k=0;
for(;b[i]!=0;i++){temp[i]=b[i];}
temp[i]=0;
for(;a[j]!=0;j++){b[j]=a[j];}
b[j]=0;
for(;temp[k]!=0;k++){a[k]=temp[k];}
a[k]=0;}

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

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

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