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;

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_swap(char* a,char* b)
{char temp[12];
for(int i=0;i<12;i++)
{temp[i]=a[i];
a[i]=b[i];
b[i]=temp[i];
}}
void string_sort(char A[][12],int n)
  {
    int i, j;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])==-1) {
           string_swap (A[j],A[j-1]);
            j = j - 1;
        }
    }
}
int main()
{int n;
cin>>n;
char A[n][12];
for(int i=0;i<n;i++)
{cin>>A[i];}
string_sort(A,n);
for(int i=0;i<n;i++)
{cout<<A[i]<<endl;
}
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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;
#define MAX 12
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_sort(char A[][MAX],int n,int &k,int &b){k=0;int j;b=0;
	for(int i=1;i<n;i++){
		j=i;
		while(j>0){if(string_compare(A[j-1],A[j])==-1){
			swap(A[j-1],A[j]);j--;k++;}
			else{b++;break;}
		}
		}
	b+=k;
}
int main(){
	int n,k,b;
	cin>>n;
	char A[n][MAX];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	string_sort(A,n,k,b);
	for(int j=n-1;j>=0;j--){
		cout<<A[j]<<endl;
	}cout<<b<<endl;
	cout<<k;

}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
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.h>
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
using namespace std;

#define MAX 200

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 insertion_sort (char A[][12], int n) {
    int i, j, k, comper=0, svap=0;
    char temp[12];
    for (i=1;i<n;i++){ // for each element of the array
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j]) < 0) { // find the location to insert it to
			// maintain a sorted subarray of i elements
//		swap(A[j],A[j-1]);
		for (k=0;k<12;k++) {
			temp[k]=A[j][k];
			A[j][k]=A[j-1][k];
			A[j-1][k]=temp[k];
		}		
            svap = svap + 1;
            j = j - 1;
        }
        comper = n;
    }
	i=0;	
	for (i=0;i<n;i++) cout<<A[i]<<endl;
    cout<<comper<<endl;
    cout<<svap<<endl;
}

int main() {
	int n=0;
	cin>>n;
	char strings[n][12];
	int i=0;
	i=0;
	for (i=0;i<n;i++) cin>>strings[n-i-1];
	insertion_sort (strings, n);
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
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[l],char*A[m])
int i=0;
while (true) {
if (A[l][i]==0 && A[m]==0) return 0;
if (A[l][i]==0) return -1;
if (A[m][i]==0) return +1;
if (A[l][i]<A[m][i]) return -1;
if (A[l][i]>A[m][i]) return +1;
i++;
}  }
void input_strings (

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
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 string_copy(char*A , char*copy){
	int t=0;
	while (a[l]=0);{
	copy [l]=a[l];
	l++;
}
copy [l]=a[l]
}
void string_compare (char*a , char*b ){
	int l=0,r=0;
	while((a[l]!=0)) && ((b[l]!=0)){
		if ((a[l]))<((b[l]))
			return 1;
	}else if ((a[l]))((b[l]))
		return -1;
	l++;
}
if (a{l}==0){
	return 1;

}
else if (b[l]==0){
	return -1;
}
else {
	return 0;
}
string_swap (char*a, char*b ){
	char temp(100);
	string_copy(a,temp);
	string_copy(b,a);
	string_copy(temp,b);
	string_sort(char(a)[100], int n){
		int l=1;
		while(l<n){
			for (int j=0, j<0,j++){
				if string_compare (A[j],A[l]==)
				{
					string_swap(A[j],A[l]);
					break;
					
				}
				l++;
			
			}
		}
	}
	void input_string(char*[A][100],int n);
	for (int l=0, l,n,l++){
						  cin>>a[l];
}
	void print_string(char*[A][100],int n );
	for (int l=0, l,n,l++){
		cout<<A[l];endl;
	}
	int main (){
		int n;
		cin>>n;
		charp[n][100];
		for (int l=0; l<n,l++){
			cin>> A[l]}
		input_string(A,n);
		string_sort(temp,n);
		printStr(lngs A,n);
		
			
	}
	
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
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 strlen(char*a){
int l=0;
while(a[l]!=0){l++;}}
void myswap(char *a,char *b){
char*temp;
for(int i=0;i<strlen(a);i++){temp[i]=a[i];}
temp[strlen(a)]=0;
for(int i=0;i<strlen(b);i++){a[i]=b[i];}
a[strlen(b)]=0;
for(int i=0;i<strlen(b);i++){b[i]=temp[i];}
b[strlen(temp)=0;}
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;
}
}
void string_sort(char**a,int n,int &p,int &q){
int i,j;q=0;p=0;
for(i=1;i<n;i++){
j=i;
while(j>0 && string_compare(a[j-1],a[j])==1){
for(int i=0;i<11;i++){myswap(a[j-1],a[j]);}q++;p++;
j--;}
while(j>0 && string_compare(a[j-1],a[j])!=1){
p++;j--;}
}}
void input(char**a,int n){
for(int i=0;i<n;i++){cin.getline(a[i],11);}}
void output(char**a,int n){
for(int i=0;i<n;i++){cout<<a[i]<<endl;}}
int main(){
char**a;int n,p,q;
cin>>n;
a=new char*[n];
for(int i=0;i<n;i++){a[i]=new char[11];}
input(a,n);
string_sort(a,n,p,q);
output(a,n);
cout<<p<<endl;
cout<<q;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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;

int strcom=0;
int swaps=0;

int string_compare(char* A, char* B){
	strcom++;
	int i=0;
	while(A[i]!=0 and B[i]!=0){
	
		if(A[i]<B[i]) return 1;
		if(A[i]>B[i]) return -1;
		i++;
	}
	if(strlen(A)<strlen(B)) return 1;
	if(strlen(A)>strlen(B)) return -1;
	return 0;
}

void ss(char* A, char* B){
	swaps++;
	for(int i=0; i<12; i++){
	
		char t=A[i]; A[i]=B[i]; B[i]=t;
	}
}

void string_sort(char A[][12], int n){

	int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        
        while (j > 0 && string_compare(A[j-1], A[j])==-1) {
            ss(A[j], A[j-1]);
            j = j - 1;
        }
    }
}


int main(){

	int n;
	cin>>n;
	char arr[n][12];
	
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	
	string_sort(arr, n);
	
	for(int i=(n-1); i > -1; i--){
	
		cout<<arr[i]<<endl;
	}
	
	cout<<strcom<<endl<<swaps;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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>//no need to pass the lenght of the string. 
using namespace std;
#define M 20
int main()
{
	int n;cin>>n;char A[M][M];
	for(int i=0;i<n;i++){cin>>A[i][M];}
	for(int i=0;i<n;i++)
	if((n>0)&&(n<15))
{
int L=0;while(A[L]!=0)l++;
if(L<12){
for(int i=0;i<n;i++){cout<<A[i][M];cout<<endl;}
cout<<n<<endl;
cout<<n/2<<endl;
}

}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
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 arr1[], char arr2[]){
int i = 0;
while (true){
if (arr1[i] == 0 && arr2[i] == 0) return 0;
if (arr1[i] == 0) return +1;
if (arr2[i] == 0) return -1;
if (arr1[i] < arr2[i]) return +1;
if (arr1[i] > arr2[i]) return -1;
i++;
}
return 0;
}
void swap(char arr1[],char arr2[]){
	char temp[12];
	for(int i=0;i<12;i++){
		temp[i]=arr1[i];
	}
	for(int i=0;i<12;i++){
                arr1[i]='\0';
        }
	for(int i=0;i<12;i++){
                arr1[i]=arr2[i];
        }
	for(int i=0;i<12;i++){
                arr2[i]='\0';
        }
	for(int i=0;i<12;i++){
                arr2[i]=temp[i];
        }
}
void string_sort(char arr[][12],int n,int &a,int &b){
	int i, j;
	int l=0;
	a=0;b=0;
	bool flag;
    	for (i=1;i < n;i++){
       		 j = i;
		 flag=false;
		 l=string_compare(arr[j-1],arr[j]);
		 b++;
       		 while (j > 0 && l==-1) {
           		 swap (arr[j],arr[j-1]);
           		 j = j - 1;
			 l=string_compare(arr[j-1],arr[j]);
			 a++;
			if(j>0) b++;
			 flag=true;
       	 	}
		
	if(flag=false) break;
	}
}
int main(){
	int n;
	cin>>n;
	char arr[n][12];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int a=0;
	int b=0;
	string_sort(arr,n,a,b);
	for(int i=n-1;i>=0;i--){
		cout<<arr[i]<<endl;
	}
	cout<<b<<endl;
	cout<<a<<endl;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A