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 &p){
int i = 0;
p++;
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;
}
int string_sort(char s[][11],int n,int &p){
int i, j,m=0;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && string_compare(s[j],s[j-1],p)==1) { 
            swap (s[j],s[j-1]);
            j--;m++;
        }
    }
return m;
}
int main(){
  int n,q,p=0;
  cin>>n;
  char s[n][11];
  for(int i=0;i<n;i++) cin>>s[i];
  q=string_sort(s,n,p);
  for(int i=n-1;i>=0;i--) cout<<s[i]<<endl;
  cout<<p<<endl<<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: 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 <cstring>
using namespace std;
#define MAX 12

void myswap(char *s1,char *s2)
{
	char temp[MAX];
	int l1=strlen(s1);
	int l2=strlen(s2);
	for (int i=0;i <= l1;i++) temp[i]=s1[i];
	for (int i=0;i<=l2;i++)s1[i]=s2[i];
	for (int i=0;i<=l1;i++)s2[i]=temp[i];

}

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_sort(char A[][MAX], int n)
{
	int i, j, x1=0,x2=0;
        for (i=1;i < n;i++)
	{
        	j = i;
        	while (j > 0)
		{
           		int p=string_compare(A[j-1],A[j]);
			x1++;
			if(p==-1)
			{
				x2++;
				myswap(A[j],A[j-1]);
			}
			else break;
            		j = j - 1;
        	}
	}
	for(int i=n-1;i>=0;i--)cout << A[i] << endl;
	cout << x1 << endl << x2;
}

int main()
{
	int n;
	cin >> n;
	if(n>14)
	{
		cout << "invalid input";
		return 0;
	}
	char A[n][MAX];
	for(int i=0;i<n;i++)cin >> A[i];
	for(int i=0;i<n;i++)
	{
		if(strlen(A[i])>11)
		{
			 cout  << "invalid input";
			return 0;
		}
	}
	string_sort(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: 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 insertion_sort(char x[][100],int n, int&no_compare,int&no_swap){
        int i,j;
        for(int i=1; i<n; i++){
            j=i;
            while(j>0 && string_compare(x[j-1],x[j])
                myswap(x[j],x[j-1]);
            j=j-1;

        
        }

    
        
}


int main(){

        int n;
        cin>>n;
        char a[n][100];
        int no_compare=0;
        int no_swap=0;
        cin>>no_compare>>no_swap;
    
        cout<<no_swap<<" "<<no_compare;

}

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<simplecpp>
using namespace std;
int main(){
int n;
void string_length (a);
    cin>>n;
	int a;
	    while(n<15 && a<11){
		    cin>> char x[a]; cin.getline(a,n);
	}
	



int string_compare(char* first, char* second){
int i=0;
while(true){
	if (first[i]==0 && second==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(int *a, int n){
	int i, j;
	for(i=1;i<n;i++){
		j=i;
		while(j>0 && a[j-1]>a[j]){
			swap(&a[j],&a[j-1]);
			j=j-1
		}
	}
	
}
		   
		  
void string_reverse(char* a, char* rev_a){
	int n= string_length(a)
		for(int i=0; i<n; i++) rev_a= a[i]
		rev_[n]=0
}

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<simplecpp>
#define max 100
int compare(char a[],char b[],int &k);
void sort(char a[][max],int n);

main_program{
	int n,i;
	cin>>n;
	char a[max][max];
	
	for(i=0;i<n+1;i++)
	scanf("%s",a[i]);
	
	sort(a,n);
}

void sort(char a[][max],int n)
{
	int i,j,k=0,p=0;
	
	
    for (i=1;i<n;i++){
    if(a[i]==0)
    {continue;}
    
        j=i;
     	while (j > 0 && (compare(a[j],a[j-1],k)==-1) ){ 
            swap (a[j],a[j-1]);
            p++;
            j = j - 1;
        }
    }
	for(i=n-1;i>=0;i--)
	{ if(a[i]==0)
    {continue;}
    
	cout<<a[i]<<endl;}
	
	cout<<k<<endl<<p;
}

int compare(char a[],char b[],int &k)
{
k++;
	int l = 0;
while (1)
{
	if (a[l] == 0 && b[l] == 0) 
	return 0;
	if (a[l] == 0) 
	return -1;
	if (b[l] == 0) 
	return +1;
	if (a[l] < b[l]) 
	return -1;
	if (a[l] > b[l])
 	return +1;
	l++;
	}
return 0;
}

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>
#define MAX 20
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 myswap(char* m,char* n){
char s[MAX];int i=0;
for(i=0;m[i]!=0;i++){
s[i]=m[i];}s[i]=0;
for(i=0;n[i]!=0;i++){
m[i]=n[i];}m[i]=0;
for(i=0;s[i]!=0;i++){
n[i]=s[i];}n[i]=0;}

void string_sort(char a[][MAX],int n,int& l,int& z){
for(int i=1;i<=n-1;i++){
for(int j=i-1;j>=0;j--){
int k=string_compare(a[j+1],a[j]);l++;
if(k==-1){myswap(a[j+1],a[j]);z++;}
if(k==+1){break;}}}}

using namespace std;
int main(){
int n;int l,z;l=z=0;
cin>>n;
char a[n][MAX];
for(int i=0;i<=n-1;i++){
cin>>a[i];}
string_sort(a,n,l,z);
for(int i=n-1;i>=0;i--){
cout<<a[i]<<endl;}
cout<<l<<endl;
cout<<z;
}

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 11
int e=0, z=0;
int string_compare(char arr[][max],int i,int j){
	e++;
	int k=0;
	while(true){
		if(arr[i][k]==0 && arr[j][k]==0) return 0;
		if(arr[i][k]==0) return -1;
		if(arr[j][k]==0) return 1;
		if(arr[i][k]<arr[j][k]) return -1;
		if(arr[i][k]>arr[j][k]) return 1;
		k++;}
		return 0;
	}
void reverse(char arr[][max],int i,int j){
	char temp[max];
	int p;
	for( p=0;arr[j][p]!='\0';p++){
		temp[p]= arr[j][p];}
	temp[p]='\0';
	int m;
	for( m =0;arr[i][m]!='\0';m++){
		arr[j][m]=arr[i][m];}
	arr[j][m]='\0';
	int b;
	for( b=0;temp[b]!='\0';b++){
		arr[i][b]= temp[b];}
	arr[i][b]='\0';}
void string_sort(char arr[][max],int n){
	int i,j;
	for(i=1;i<n;i++){
		j=i;
		
		while(j>0 && string_compare(arr,j,j-1)==1){
			z++;
			reverse( arr,j-1,j);
			j=j-1;
		}
	}
}

int main(){
int n;
cin>>n;
char arr[n][max];
for(int u=0;u<n;u++){
	cin>>arr[u];}
string_sort(arr,n);
for(int k=0;k<n;k++){
	for(int j=0;arr[k][j]!='\0';j++){
		
		cout<<arr[k][j];}
	cout<<"\n";}
cout<<e-2<<"\n"<<z-2;
	}

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>
#define max 100
using namespace std;
int count=0;
void swap(char*&a,char*&b){

char t[max];
int i=0;

while(a[i]!='\0'){
t[i]=a[i];i++;}
t[i]='\0';

i=0;

while(b[i]!='\0'){
a[i]=b[i];i++;}
a[i]='\0';

i=0;

while(t[i]!='\0'){
b[i]=t[i];i++;}
b[i]='\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 insertion_sort (char a[][max], int n) {
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        int num=string_compare(a[j],a[j-1]);
        while (j > 0 && (num==-1)) {
            count++; 
            swap (a[j],a[j-1]);
            j = j - 1;
        }
    }
}

int main(){
int n;
cin>>n;
char arr[n][max];
for(int i=0;i<n;i++){
cin>>arr[i];
}
insertion_sort(arr,n);
for(int i=n;i>0;i--){
cout<<arr[i]<<endl;}
cout<<count;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: B