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 N=11;

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 str_swap(char* a, char *b){
    char * temp;
    while(*temp++=*a++);
    while(*a++=*b++);
    while(*b++=*temp++);
}
void string_sort(char a[][N],int n,int &k,int &l){

    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        
        while (j>0 && string_compare(a[j],a[j-1])==-1) { 
            swap (a[j],a[j-1]);
            j = j - 1;
            k=k+1;
            l=l+1;
            if (string_compare(a[j],a[j-1])!=-1) k=k+1;
        }}
        
    }




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

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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 I=0;
int length(char *c)
{
	int i=0;
	while(c[i]!=0)
	i++;

	return i;
}

int string_compare(char *a,char *b)
{
	I++;
	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++;
	}
	return 0;
}
void string_sort(char c[][12],int n,int &s)
{
	int i,j,k;
	for(int i=1;i<n;i++)
	{
		j=i;
		while(j>0 && string_compare(c[j-1],c[j])==-1)
		{
		char temp[12];
		for(k=0;k<=length(c[j]);k++)
		temp[k]=c[j][k];

		for(k=0;k<=length(c[j-1]);k++)
		c[j][k]=c[j-1][k];

		for(k=0;k<=length(temp);k++)
		c[j-1][k]=temp[k];

		s++;

		j--;
		}
	}
}

int main()
{
	int n,s=0;
	cin>>n;

	char c[n][12];
	for(int i=0;i<n;i++)
	cin>>c[i];

	string_sort(c,n,s);

	for(int i=n-1;i>=0;i--)
	cout<<c[i]<<endl;

	cout<<I<<endl<<s;
	return 0;
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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 20
using namespace std;
int nswap=0;
int ncomp=0;
void mswap (char *a, char *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int string_compare (char *f, char * l){
int i = 0;
ncomp++;
for (;;){
if (f[i] == 0 && l[i] == 0) return 0;
if (f[i] == 0) return -1;
if (l[i] == 0) return +1;
if (f[i] < l[i]) return -1;
if (f[i] > l[i]) return +1;
i++;
}
return 0;
}
void string_sort (char A[MAX][MAX], int n)
{
   int i, j;

    for (i=1;i < n;i++)
    {
        j = i;
        
        while (j > 0 && string_compare(A[j-1],A[j])==1)
        {nswap++;
           for (int k=0;k<MAX && (A[j][k]!=0||A[j-1][k]!=0);k++){ mswap (&A[j][k],&A[j-1][k]);}
            j = j - 1;
	}
    }
}
int main(){
int n;
cin>>n;
char a[MAX][MAX];
for(int i=0;i<n;i++){for (int j=0;j<n;j++){a[i][j]='\0';}}
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<<ncomp<<endl<<nswap;
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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 swaps=0;
int compare=0;
void input(char a[][max],int n)
{
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void output(char a[][max],int n)
{
for(int i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}
void swapss(char a[],char b[])
{
swaps++;
char temp[max];
int i=0;
while(a[i]!=0)
{
temp[i]=a[i];
i++;
}
temp[i]=a[i];
i=0;
while(b[i]!=0)
{
a[i]=b[i];
i++;
}
a[i]=b[i];
i=0;
while(temp[i]!=0)
{
b[i]=temp[i];
i++;

b[i]=temp[i];
}
}
int string_compare(char a[],char b[])
{compare++;
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 reverse(char a[][max],int n)
{
for (int i=0;i<n/2;i++)
{
swap(a[i],a[n-1-i]);
}
}

void string_sort(char a[][max],int n)
{
int i,j;
for(int i=1;i<n;i++){

j=i;
	while(j>0&&string_compare(a[j-1],a[j])==-1)
	{
	swapss(a[j-1],a[j]);
	j--;
	}
	}
	/*int j=0;
	while(j<i&&string_compare(a[i],a[j])==-1)
	{
	swapss(a[i],a[j]);j++;
	}}*/
	
}

int main()
{
int n;
cin>>n;
char a[n][max];
input(a,n);
string_sort(a,n);
reverse(a,n);
output(a,n);
cout<<compare<<endl<<swaps;

}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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<cstring>
using namespace std;
#define mx 12

int string_compare(char *a,char*b,int &w){
	int i=0;w++;
	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 swap2(char * a,char *b){
	char temp[12];
   strcpy(temp,a);strcpy(a,b);strcpy(b,temp);

}

void string_sort(char a[][mx],int n, int &t,int &w){
	 int i, j;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && string_compare(a[j-1], a[j],w)==1) { 
            swap2 (a[j],a[j-1]);t++;
            j = j - 1;
                                                         }
                         }
                                       }
int main(){
	int n,t=0,w=0;
	cin>>n;
	char a[n][mx];
	for(int i=0;i<n;i++) cin>>a[i];
	string_sort(a,n,t,w);
	for(int i=n-1;i>=0;i--) cout<<a[i]<<endl;
	cout<<w<<endl<<t;
}
/*
void swap2(char * a,char *b){
	char temp[12];
   strcpy(temp,a);strcpy(a,b);strcpy(b,temp);

}
int main(){
	char a[]="adfg";char b[]="xcfe";
	swap2(a,b);
	cout<<b; // this was just rough work
}*/

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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 *s1, char *s2){
	int i = 0;
	while(true){
		if(s1[i] == 0 && s2[i] == 0){
			return 0;
		}
		if (s1[i] == 0){
			return 1;
		}
		if (s2[i] == 0){
			return -1;
		}
		if (s1[i] > s2[i]){
			return -1;
		}
		if (s2[i] > s1[i]){
			return 1;
		}
		i++;
	}
}


void string_sort(char**s, int n){
	int compares = 1, swaps = 0;
	int i, j;
	for(int i = 1; i<n; i++){
		j = i;
		compares++;
		while(j>0 && string_compare(s[j-1], s[j]) == -1){
 			char * temp = s[j];
 			s[j] = s[j-1];
 			s[j-1] = temp;
 			swaps++;
			j = j-1;
		}
	}	
	for(int i = n-1; i>=0; i--){
		cout << s[i] << "\n";
	}
	cout << compares << "\n" << swaps;
}

int main(){
	int n; cin >> n;
	char ** s =  new char*[n];
	for(int i = 0; i<n; i++){
		char *t = new char[12];
		cin >> t;
		s[i] = t;
	}
	string_sort(s, n);
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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<string>
using namespace std;
# define MAX 100

int compare=0;
int sort=0;

int string_compare (char A[], char B[]){
compare = compare + 1;
if (A>B) return 1;
else if (A<B) return -1;
else return 0;
}

void string_sort (char A[][MAX], int n){
 int i, j;
 for (i=1;i < n;i++){ // for each element of the array
  j = i;
  while (j > 0) { 
string_compare(A[j], A[j-1]);


if (string_compare==1){
	sort +=sort;
  swap (&A[j],&A[j-1]);
            j = j - 1;
        }
    }}
}

int main(){
int n;
cin>>n;
char string[8];

char strings[n][8];

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



}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
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>
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 stringreverse(char *s1, char* s2){
char s[100];
//for(int i=0;i<100;i++){
//s[i]="0";
//}
for(int i=0;i<100;i++){
s[i]=s1[i];s1[i]=s2[i];s2[i]=s[i];
}}
void stringsort(char A[][100],int n,int &l,int&m){
    int i, j;l=-1;m=0;
    for (i=1;i < n;i++){ 
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])==-1) { 
	
            stringreverse (A[j-1],A[j]);m++;
            j = j - 1;
        }l++;
    }

}

main_program{
int n,l,m;

cin>>n;
char A[n][100];
//for(int i=0;i<n;i++){
//(int j=0;j<n;j++){A[i][j]="0";}
//}
for(int i=0;i<n;i++){cin>>A[i];}
stringsort(A,n,l,m);
for(int i=0;i<n;i++){cout<<A[i]<<endl;}
cout<<m<<endl;
cout<<l<<endl;



}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A