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;
#define MAX 100
int swaps=0;
int compare=0;
int string_compare (char *first, char * second){
	compare++;
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[][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) { 
            swap (A[j],A[j-1]);
            j = j - 1;
			swaps++;
        }
    }
}

int main(){
	int n; cin>>n;
	char A[MAX][MAX];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	insertion_sort(A,n);
	for(int i=n-1;i>-1;i--){
		cout<<A[i]<<endl;
	}
	cout<<compare<<endl<<swaps;
	return 0;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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;
void input(char *&A,int n)
{
for(int i=0;i<n;i++)
{
cin >> A[i];
}
}
int string_compare(char *f, char *s)
{
int i=0;
while (true)
{
if (f[i]==0 && s[i]==0) return 0;
if (f[i]==0) return -1;
if (s[i]==0) return +1;
if (f[i]<s[i]) return -1;
if (f[i]>s[i]) return +1;
i++;
}
return 0;
}
void string_sort(char A[][MAX], int n)
{
int i,j,k=0;
char t[MAX];
for(k=0;A[j]!=0;k++)
{t[k]=A[i][j]
for(i=1;i<n;i++)
{
j=i;
while (j>0 && A[j-1]>A[j])
{
t=A[j-1];
A[j-1]=A[j];
A[j]=t;
j=j-1;
}
}
}
void string_print(char A[][MAX], int n)
{
for(int i=n-1;i>=0;i--)
{
cout << A[i] << '\n';
}
}
int main ()
{
int n;
cin >> n;
char A[n][MAX];
input(char A[n][MAX], int n);
string_sort(char A[n][MAX], int n);
string_print(char A[n][MAX], int n);

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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 strcompare=0;
int strswap=0;
void input(char s[][MAX],int n){
        for(int i=0;i<n;i++){
		cin>>s[i];
                /*for(int j=0;j<MAX;j++){
                        cin>>s[i][j];
                        }*/
                }
        }
int string_compare(char a[],char b[]){
	strcompare++;
	int na=0;int nb=0;
	while(a[na]!=0 && b[nb]!=0 && na<MAX && na<MAX){
		if(a[na]<b[nb]){return 1;}
		else if(a[na]>b[nb]){return -1;}
		else{na++;nb++;}
		}
	if(a[na]){return -1;}
	else if(b[nb]){return 1;}
	else{return 0;}
	}
void myswap(char s[][MAX],int i,int j){
	for(int x=0;x<MAX;x++){
		char temp=s[i][x];
		s[i][x]=s[j][x];
		s[j][x]=temp;
		}
	strswap++;
	}
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-1],a[j])==-1){
            		myswap(a,j,j-1);
            		j=j-1;
			}
    		}
	}
void output(char s[][MAX],int n){
	for(int i=n-1;i>=0;i--){
		int j=0;
		while(s[i][j] && j<MAX){
			cout<<s[i][j++];
			}
		cout<<endl;
		}
	}
int main(){
int n;cin>>n;
char s[n][MAX];
input(s,n);
//for(int i=0;i<MAX;i++){if(!s[0][i])break;cout<<s[0][i];}
string_sort(s,n);
output(s,n);
cout<<strcompare<<endl<<strswap;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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
using namespace std;

int comparisons=0, swaps=0;

int string_compare(char* str1, char* str2){
	int i = 0;
	comparisons += 1;
	while (true){
		if (str1[i] == 0 && str2[i] == 0) return 0;
		if (str1[i] == 0) return 1;
		if (str2[i] == 0) return -1;
		if (str1[i] < str2[i]) return 1;
		if (str1[i] > str2[i]) return -1;
		i++;
	}
}

void string_swap(char*& str1, char*& str2){ 
	char* temp = str1; 
	str1 = str2; 
	str2 = temp; 
}

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

void print_reversematrix(char A[][MAX], int n)
{
	for(int i=0; i<n; i++){cout<< A[n-1-i] << endl;}
}

int main()
{
	int n; cin>>n;
	char A[n][MAX];
	for(int i=0; i<n; i++){cin>> A[i];}
	
	string_sort(A,n);
	print_reversematrix(A,n);
	cout<< comparisons <<'\n' << swaps;		
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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 11
#include<cstdlib>
using namespace std;
int string_compare(char s1[], char s2[]){
int i=0;
while (true){
if (s1[i] == '\0' && s2[i] == '\0') return 0;
else if (s1[i]== '\0') return 1;
else if (s2[i] == '\0') return -1;
else if (s1[i] > s2[i]) return -1;
else if (s1[i] < s2[i]) return 1;
i++;
}
return 0;
} 
void string_sort(char s[][MAX], int n, int &k, int&l){
int i, j;
for (i=1; i < n; i++){
j = i;
while (j > 0){
if (string_compare(s[j], s[j-1]) == 1) {
swap(s[j],s[j-1]);
k++; 
l++;
}
else {
k++;
break;
}
j--;
}
}
}
int main(){
int n;
cin >> n;
char s[n][MAX];
for (int a=0; a < n; a++){
cin >> s[a];
}
int k,l;
k = l=0;
string_sort(s,n,k,l);
for (int a=n-1; a > -1; a--){
cout << s[a] << endl;
}
cout << k << endl << l;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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 x=0;
int y=0;
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_swap(char A[][MAX], int j){
    
    char temp[12];
    string_copy(temp,A[j]);
    string_copy(A[j],A[j-1]);
    string_copy(A[j-1],temp);
}
int string_compare (char *first, char * second){
    ::x++;
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 i, j;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])<0) {
            string_swap(A,j);
            j = j - 1;
            ::y++;
        }
    }
    

}

int main(){
    int n;
    cin>>n;
    char strings[MAX][MAX];
    for (int i=0;i<n;i++){
        cin>>strings[i];
    }
    string_sort(strings,n);
    for (int i=n-1;i>=0;i--){
        cout<<strings[i]<<endl;
    }
    cout<<::x<<endl<<::y;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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;
#define MAX 100

int sc=0;
int ss=0;

void input (char A[][MAX], int n){
int i;
for(i=0;i<n;i++){
                        cin>>A[i];
                }

}

void output (char A[][MAX], int n){
int i;
for(i=n-1; i>-1;i--){
cout<<A[i];
cout << endl;
}
}

int string_compare (char *first, char * second){
sc++;
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 i, j;
    for (i=1;i < n;i++){
        for(j=i; j>0 && string_compare(A[j-1],A[j])==-1; j--) {
            swap (A[j],A[j-1]);
            ss++;
         }
    }
}

int main(){
int n; cin>>n;
char A[MAX][MAX];
input(A,n);
string_sort(A,n);
output(A,n);
cout<<sc<<endl;
cout<<ss;}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
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 15
using namespace std;
int string_compare (char *first, char * second, int &m)
{
m = 0;
while (true){
if (first[m] == 0 && second[m] == 0) return 0;
if (first[m] == 0) return +1;
if (second[m] == 0) return -1;
if (first[m] < second[m]) return +1;
if (first[m] > second[m]) return -1;
m++;
}
return 0;
}
void string_sort (char A[MAX], int n, int &temp, int &m)
{
 temp = 0;
 int i,j;
 for (int i = 0; i < n; i++)
 {
  j = i;
  while ((j>0) && (string_compare (&A[j-1], &A[j], m) < 0)) 
  {
  swap (A[j], A[j-1]);
  j = j - 1;
  temp += 1;
  }
 } 
}
int main()
{
 int n;
 cin>>n;
 int temp;
 int m;
 char A[MAX];
 cin.getline (A, n);
 for (int k = 0; k < n; k++) cin>>A[k];
 string_sort (A, n, temp, m);
 for (int i = n-1; i >= 0; i++)
 {
  cout<<A[i]<<endl;
 }
 cout<<m<<endl<<temp;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A