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;
void myswap(char *x, char *y){
	char z[100];
	for(int i=0;i<100;i++){
		z[i]=x[i];
	}
	for(int i=0;i<100;i++){
		x[i]=y[i];
	}
	for(int i=0;i<100;i++){
		y[i]=z[i];
	}
}
int strcomp(char *x, char *y){
	int i=0;
	while(true){
		if(x[i]==0 && y[i]==0) return 0;
		if (x[i]==0) return 1;
		if (y[i]==0) return -1;
		if (x[i]<y[i]) return 1;
		if (x[i]>y[i]) return -1;
		i++;
	}
}
void insertionsort(char a[100][100], int n, int &count1, int &count2){
	for(int i=1;i<n;i++){
		for(int j=i; j>0;j--){
			count1++;
			if (strcomp(a[j],a[j-1])==1) {myswap(a[j],a[j-1]); count2++;}
			else break;
		}
	}
}
void inputstrings( char a[100][100], int n){
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
}
void outstrings( char a[100][100], int n){
	for (int i=n-1;i>=0;i--){
		cout<<a[i]<<endl;
	}
}
int main(){
	int n;
	cin>>n;
	char a[100][100];
	int count1=0;
	int count2=0;
	inputstrings(a,n);
	insertionsort(a,n,count1,count2);
	outstrings(a,n);
	cout<<count1<<endl<<count2;
}

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 12
#define MAX1 15
using namespace std;

void swap(int*&a, int*&b){
	int *temp = a;
	a = b;
	b = temp;
}

bool arr_input(int arr[MAX1][MAX], int n){
		for(int i =0; i<n; i++) {
		cin >> arr[i];
		int k =0; bool cond;
		while(arr[i][k]){
			cond = !('a'<=arr[i][k] && arr[i][k] <='z');
			if(cond){
				cout << "Invalid Input";
				return cond;
			} 
			k++;
		}
	}
}


int string_compare(char*s1, char*s2){
	int i=0;
	while(true){
		if(s1[i]<s2[i]) return 1;
		else if(s2[i] < s1[i]) return -1;
		i++;
	}
	return 0;
}

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


int main(){
	int n;
	cin >> n;
	char arr[MAX1][MAX];
	bool cond = arr_input(arr, n);
	if(cond){
		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 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: 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 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: 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;
#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: 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<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: 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: 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;
#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: 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<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: 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