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 12
using namespace std;

int comp_c=0,swap_c=0;

void sw(int a,int b,char s[][MAX]){
swap_c++;
char dum[12];

for(int i=0;i<12;i++){
    dum[i]=s[a][i];
}

for(int i=0;i<12;i++){
    s[a][i]=s[b][i];
}

for(int i=0;i<12;i++){
    s[b][i]= dum[i];
}

}


int cs(int a,int b,char s[][MAX]){
comp_c++;
int i=0;

while(true){

if(s[a][i] == '\0' && s[b][i] == '\0')return 0;
if(s[a][i] == '\0')return 1;
if(s[b][i] == '\0')return -1;
if(s[a][i] > s[b][i])return -1;
if(s[a][i] < s[b][i])return 1;
i++;

}
return 0;

}

void ss(char s[][MAX],int n){

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

for(int i=1;i<n;i++){
    for(int j=i;j>0;j--){
        if( cs(j-1,j,s)!= -1 )break;
        sw(j-1,j,s);
    }
}

}

int main(){

int n;cin>>n;

char s[n][MAX];

ss(s,n);

for(int i=n-1;i>=0;i--){
    cout<<s[i]<<endl;
}
cout<<comp_c<<endl<<swap_c<<endl;
}

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;

int compare=0,swaps=0;

void swap(string *a,string *b){
   string *temp;
   *temp=*a;
   *a=*b;
   *b=*temp; }
 
int string_compare (char *first, char * second){
 int i=0;
while (true){
if (first[i] == 0 && second[i] == 0) {compare++; return 0;}
if (first[i] == 0) {compare++;return -1;}
if (second[i] == 0) {compare++; return +1;}
if (first[i] < second[i]) {compare++;  return -1;}
if (first[i] > second[i]) {compare++; return +1;}  }
return 0; }

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

int main(){
   int n; cin>>n;
   char str[100][12];
   for(int i=0;i<n;i++){
     cin>>str[i];}
    string_sort(n,str);
if(n<15){
  for(int i=n-1;i>=0;i--){
    cout<<str[i]<<endl; }
  cout<<compare<<endl<<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: 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 *first, char * second){
int i = 0;
while (true){
if (first[i] == second[i] return 0;
if (first[i] < second[i]) return +1;
if (first[i] > second[i]) return -1;
i++;
}
int insertion_sort (int *A, int n) {
    int i, j;
    int count=0;
    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]);
            count=count+1;
            j = j - 1;
        }
    }
return count;
}
}
int main(){
int n;
cin>>n;
char **A= new char*[n];
for (i=0;i<n;i++){
     A[i]=new char[n];}
for (i=0;i<n;i++){
      cin>>A[i];}
insertion_sort(A,n);
for (i=0;i<n;i++){
      cout<<A[i];}
int count=insertion_sort(A,n);
cout<<count;

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: 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 s=0;
int string_compare(char* a,char* b){
int i=0;
while(true){
if(a[i]==b[i]) 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 *A, int n) {
    int i, j,s=0;
    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;
		s++;
        }
    }
}
int main(){
int n;
cin>>n;
input[n][11];
for(int i=0;i<n;i++){
cin>>input[i][11];
}
string_sort(input,n);
for(int i=0;i<n;i++){
cout<<input[i][11];
}
cout<<s;
}

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:
//22B1068


#include <iostream>
using namespace std;
#define MAX 12

//global variables
int comp_count = 0, swap_count = 0;

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

void printstring(char mystr[][MAX], int n){
	for (int i = n - 1; i >= 0; i--){
		cout << mystr[i] << "\n";
	}
}


int string_compare(char s1[], char s2[]){
	comp_count++;
	int c = 0; // counter
	while(s1[c] && s2[c]){
		if (s1[c] < s2[c])
			return 1;
		if (s2[c] < s1[c])
			return -1;
		c++;
	}
	if (s1[c] == 0 && s2[c] != 0)
		return 1;
	if (s1[c] != 0 && s2[c] == 0)
		return -1;


	return 0;
}

void string_sort(char s[][MAX], int n){  //using insertion sort
	for (int i = 1; i < n; i++){
		for (int j = i - 1; j >= 0; j--){
			
			if(string_compare(s[j+1], s[j]) != 1)
				break;
			swap(s[j+1], s[j]);
			swap_count++;
		}
	}
}


int main(){
	int n;
	cin >> n;
	char mystr[n][MAX];
	getstring(mystr, n);
	//printstring(mystr, n);
	string_sort(mystr, n);
	printstring(mystr, n);
	cout << comp_count << "\n" << swap_count;
}

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<string>
using namespace std;
int n1=0;
int string_compare(string s1,string s2)
{
n1++;
if(s1>s2)
return -1;
else if(s2>s1)
return 1;
else
return 0;
}

void string_sort(string s[],int n)
{
int i, j,swap=0;
    for (i=1;i < n;i++)
    {
        j = i;
        while (j > 0 && string_compare(s[j-1],s[j])==-1)
         {
         string temp;
         temp=s[j-1];
         s[j-1]=s[j];
         s[j]=temp;
            j = j - 1;
            swap++;
        }
}
for(i=0;i<n;i++)
cout<<s[n-i-1]<<endl;
cout<<n1<<endl<<swap;
}

int main()
{
int n;
cin>>n;
char c[n][12];
for(int i=0;i<n;i++)
cin>>c[i];
string s[n];
for(int i=0;i<n;i++)
s[i]=c[i];
string_sort(s,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;

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: 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 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: 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 <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: 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