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* a,char* b)
{   for(int j=0;j<11;j++)
    {    if(a[j]==0&&b[j]==0)return 0;
         else if(b[j]==0)return 1;
         else if(a[j]==0)return -1;
         else if(a[j]>b[j])return 1;
         else if(b[j]>a[j])return -1;
     }return 0;
}
void string_copy(char* a,char* b)
{    int i;
     for(i=0;a[i]!=0;i++)
     b[i]=a[i];
     for(int j=i;j<12;j++)
     b[j]=0;
}
void string_swap(char* a,char* b)
{    char c[12];
     string_copy(a,c);string_copy(b,a);
     string_copy(c,b);
}
void string_sort(char a[][12],int n,int& x,int& y)
{
int i,j;
for(int i=1;i<n;i++)
  {j=i;
   while(j>0 && string_compare(a[j-1],a[j])<0)
    {string_swap(a[j],a[j-1]);
    j--;x++;y++;}
   y++;}
}
int main()
{
int n,x=0,y=0,b=0;cin>>n;
char a[n][12];
while(cin.getline(a[b++],12));
string_sort(a,n,x,y);
for(int i=0;i<n;i++)
cout<<a[i]<<endl;
cout<<y<<endl<<x; 
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;

int string_compare(char* A, char* B)
{
	int i=0;
	while((A[i] != '\0') && (B[i] !='\0'))
	{
		if(A[i] > B[i])
			return 1;
		else if (A[i] < B[i])
			return -1;
		i++;
	}
	if(A[i] == B[i]) //checking if both are null
		return 0;
	else if(A[i] == 0)
		return -1;
	else
		return 1;
}

void string_sort(char A[][12],int n,int& swap,int& compare)
{
	for(int i = 1; i < n;i++)
	{
		int j = i;
		while((j > 0) && (compare++ >= 0)&& (string_compare(A[j-1],A[j]) == -1))//to increase compare
		{
			swap++;int k;
			char temp[12];
			for(k = 0; A[j][k] != 0; k++)
				temp[k] = A[j][k];
			temp[k] = 0;
			for(k = 0; A[j-1][k] != 0; k++)
				A[j][k] = A[j-1][k];
			A[j][k] = 0;
			for(k = 0; temp[k] != 0; k++)
				A[j-1][k] = temp[k];
			A[j-1][k] = 0;
			//strcpy(temp,A[max_index]);
			//strcpy(A[max_index],A[i]);
			//strcpy(A[i],temp);
			j--;
		}
		if(j == 0)
			compare--;
	}
}

int main()
{
	int n,swap = 0,compare = 0;
	cin >> n;
	char words[n][12];
	for(int i =0; i<n ; i++)
		cin >> words[i];
	string_sort(words,n,swap,compare);
	for(int i =0; i < n; i++)
		cout << words[i] << '\n';
	cout<< compare << '\n' << swap;
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
#include<cstring>
using namespace std;

#define max 100
int string_compare(char* a,char* b)
{
	int i=0;
	if(a[i]==0 && b[i]!=0)return 1;
	if(a[i]!=0 && b[i]==0)return -1;
	if(a[i]==0 && b[i]==0)return 0;
	while(a[i]!=0 && b[i]!=0)
	{
		if(a[i]>b[i]) return -1;
		if(a[i]<b[i]) return 1;
		i++;
	}
	if(a[i]==0 && b[i]!=0) return 1;
	if(a[i]!=0 && b[i]==0) return -1;
	if(a[i]==0 && b[i]==0) return 0;
}
void insertion_sort(char a[][max],int n)
{
	int i,j;
	for(i=1;i<n;i++)
	{
	 j=i;
	while(j>0)
	{
	if(string_compare(a[j-1],a[j])==-1) 
		{
		char* e=a[j-1];
		char *f=a[j];
		a[j]=e;
	a[j-1]=f;
		
		}
	j--;
	}
	}
}

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>=0;i--)
	{
	 cout<<a[i]<<endl;
	}
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;
int stringCompare(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++;
c++;
}
return 0;


}

void insertionSort(int *A,int n){
int i,j;
for(i=0;i<n;i++){
	j=i
	while(j>0 && A[j-1]>A[j]){
		swap(&A[j],&A[j-1]);
		j=j-1;
		}
	}

}
int string_length (char *x)
{
	int L = 0;
	while (x[L] != ‘\0’) L++;
return L;
}
void stringReverse(char *s,char *rev_s){

	int n=string_length(s);
	for(int i=0;i<n;i++){
	rev_s[n-i-1]=s[i];
	rev_s[n]=0;

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

return 0;
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: 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;
const int MAX = 100;

int string_compare(char *a, char *b,int& compare_count){
	int i = 0;	
	compare_count++;
	while(a[i]!='\0' && b[i] != '\0' ){
		if(a[i]<b[i]) return 1;
		else if(a[i]>b[i]) return -1;
		else i++;
	}

	if(a[i] != '\0') return 1;
	else if(b[i] != '\0') return -1;
	else return 0;

}

void string_sort(char **s,int n,int& compare_count,int& swap_count){
	
	int i,j;
	for(int i = 1; i<n; i++){
		j = i;
		
		bool flag = false; 

		while(j>0 && string_compare(s[j-1], s[j], compare_count) == -1){
			flag = true;
			char *c = s[j-1];
			s[j-1] = s[j];
			s[j] = c;
			j--;
			swap_count++;
		}
	}
}

int main(){

	int n;
	cin >>n;
	char d[n][MAX];
	char *s[n];

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

	int compare_count = 0, swap_count = 0;

	string_sort(s,n,compare_count,swap_count);
	for(int i = n-1; i>=0;i--){
		cout<<s[i]<<'\n';
	}
	cout<<compare_count<<'\n'<<swap_count;
	
}

Grading criterion: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;

int string_compare (char *first, char * second,int &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: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include <iostream>
#include <cstring>
using namespace std;
#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: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;

int string_compare(char*first, char*second){
        int i=0;

        while(true){

        
        if(first[i] == 0 && second[i] == 0) return 0;

        if(first[i] == 0) return -1;
        if(second[i] == 0) return +1;
        if( first[i]< second[i]) return -1;
        if( first[i]> second[i]) return +1;
        i++;
        }
        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: Sort implemented not in function
Rating A: If separate function is used and function signature is correct
Rating B: If separate function is used but function signature is not correct
Rating C: 0
Rating D: 0
Assigned grade: B