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>
#include<cmath>
using namespace std;
#define max 15
int string_compare(char *str1,char *str2)
{
int n=min(sizeof(str1),sizeof(str2));
for (int i=0;i<n;i++)
{
if (str1[i]==str2[i]) return 0;
else if (str1[i]<str2[i]) return 1;
else if (str1[i]>str2[i]) return -1;
}
}
void string_sort(char A[max][max],int n)
{
int count_swap=0,count_compare=0;
for (int i=0;i<n;i++)
{
 int j=i;
 while (j>0)
 {
  int res=string_compare(A[j-1],A[j]);
  count_compare+=1;
  if (res==-1)
  {
   char* temp=A[j-1];
   *A[j-1]=*A[j];
   *A[j]=*temp;
   count_swap+=1;
  }
}
}
}

int main(){
int n;
char A[max][max];
cin>>n;
for (int i=0;i<n;i++) cin>>A[i];
string_sort(A,n);
int i=0;
while (A[i]!=0)
{
cout<<A[n-1-i]<<endl;
i++;
}
}

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 k=0;
int m=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];
	}
int string_compare (char *first, char * second){
int i = 0;k++;
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[][12],int n){
for(int i=0;i<n;i++){for(int j=i;j>0;j--){
if(string_compare(A[j],A[j-1])==-1){char b[12];string_copy(b,A[j]);
string_copy(A[j],A[j-1]);string_copy(A[j-1],b);m++;}
else break;}}
}
int main(){
int n;
cin>>n;
char A[15][12];
for(int i=0;i<n;i++){cin>>A[i];}
string_sort(A,n);
for(int i=n-1;i>=0;i--){cout<<A[i]<<endl;}
cout<<k<<endl;
cout<<m;}

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;
const int MAX=1000;
int strcmpr=0;
int numswaps=0;
void swap(char &a,char &b){
	char temp=a;
	a=b;
	b=temp;
	return;
}
int string_compare(char *a,char *b){/*gives 1 if a come first -1 if b comes first*/
	int num=0;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;
		}else if (a[i+1]==0 && b[i+1]!=0){
			return 1;
		}else if (a[i+1]!=0 && b[i+1]==0){
			return -1;
		}
		i++;
	}
	return num;
}
void string_sort(char a[][MAX],int n){
	for (int i=1;i<n;i++){
		for (int j=i;j>0;j--){
			bool fg=0;
			int c=string_compare(a[j-1],a[j]);
			strcmpr++;
			if (c==-1){
				int k=0;
				while(a[j-1][k]!=0 || a[j][k]!=0){
					swap(a[j-1][k],a[j][k]);
					k++;
				}
				fg=1;
				numswaps++;
			}
			if (!fg){
				break;
			}
		}
	}
	return;
}
int main (){
	int n;
	cin >>n;
	char a[n][MAX];
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	string_sort(a,n);
	for (int i=0;i<n;i++){
		cout << a[n-1-i]<<endl;
	}
	cout <<strcmpr<<endl<<numswaps<<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: 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 k=0,o=0;
void swap(char *a,char *b){
    char temp=*a;
    *a=*b;
    *b=temp;
    k=k+1;
}

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

void insertion_sort (char A[][11], int n) {
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
       
        while (j > 0 && int strcmp(A[j-1][11],A[j][11])>0) {
          
 swap (&A[j][11],&A[j-1][11]);
            j = j - 1;
            o=o+1;
        }
    }
}

void print(char A[][11],int n){
  for(int i=n-1;i>=0;i++){
      cout<<A[i][11]<<endl; 
  }
  cout<<o<<endl;
  cout<<k<<endl;
}

int main(){
    int n;
    cin>>n;
    char A[n][11];
    input(A,n);
    insertion_sort(A,n);
    print(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: 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<simplecpp>
int string_compare(char A,char B){
	if(A>B){return -1;}
	if(B>A){return 1;}
	else{return 0;}
}

main_program{
 int n,i,j;
 cin>>n;
 char A[n][11];
 for(i=0;i<n;i++){
	for(j=0;j<11;j++){
		cin>>A[i][j];
	}
 }
}

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: 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;
#define MAX 10000
char **allocate_2d (int n1, int n2){
	char **A = new char*[n1]; // array of n1 int* variables
	for(int i=0;i<n1;i++){
		A[i] =  new char [n2]; // array of n2 int variables
	}
	return A;
}

void string_copy (char* dest, char* source) {
	int i;
	for(i=0;source[i] != '\0';i++){
		dest[i] = source[i];
	}
	dest[i] = source[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++;
}
return 0;
}

void insertion_sort (char* A[12], int n) {
    int i, j;
    int a,b;
    a=b=0;
    for (i=0;i < n;i++){ // for each element of the array
        j = i;
        while (j >= 0)  { 
	     if(string_compare(A[j],A[j+1]) == -1){
            char t[20];
            string_copy(t,A[j]);
            string_copy(A[j],A[j+1]);
            string_copy(A[j+1],t);}
            a++; 
            }
            j = j - 1;
        b++;  
        }
        
        
    
    for(int j=0;j<n;j++){
	cout<<A[j]<<endl;}
	cout<<b<<endl<<a;
	
}
int main(){
	int n;
	cin>>n;
	char **ch= allocate_2d(15,12);
	
	for(int i=0;i<n;i++){
	cin>>ch[i];
	}
		
	insertion_sort(ch,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: 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>
#include<string>
using namespace std;

  int string_compare(char *string1,char *string2){
  
  int i=0;
  int j=0;
   while(true){
   if(string1[i]<string[j]) return -1;
   if(string1[i]>string[j]) return 1;
    }
    
    int string_reverse(char *string1, char *rev_string1){
      int n=string_length(string1);
      for(int i=0;i<n;i++){
      rev_string1[n-1-i]=string1[i];
      rev_string1[n]=0
      }
      
      int main(){
      cin>>string1>>string2;
      cout<<string_reverse(string1,string2);
      }

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: 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;
#define MAX 12
int comp = 0, swop = 0;
int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) {comp++;return 0;}
if (first[i] == 0) {comp++;return -1;}
if (second[i] == 0) {comp++;return +1;}
if (first[i] < second[i]) {comp++;return -1;}
if (first[i] > second[i]) {comp++;return +1;}
i++;
}
return 0;
}
void 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]);
			swop++;
			j=j-1;
		}
	}
}
void display(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];}
	sort(a,n);
	display(a,n);
	cout << comp << "\n"<<swop;
	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: 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 l=0,m=0;


int compare (char *first, char * second){
int i = 0;l++;
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 swap(char *a1,char *a2){
m++;
for(int i=0;i<12;i++){char temp=a1[i];a1[i]=a2[i];a2[i]=temp;}
}
void sort(char a[][12],int n){
for(int i=1;i<n;i++){int j=i;
while (j > 0 && compare(a[j-1],a[j])==1){swap(a[j],a[j-1]);j--;}
}
}
int main(){
int n;cin>>n;
char a[n][12];
for(int i=0;i<n;i++)cin>>a[i];
sort(a,n);
for(int i=n-1;i>=0;i--)cout<<a[i]<<endl;
cout<<l<<endl<<m;
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: A