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 100
using namespace std;
int x=0;
int y=0;
void string_copy (char *dest, const char* source) {
	int i;
	for(i=0;source[i]!= '\0';i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}
void string_swap(char A[][MAX], int j){
    
    char temp[12];
    string_copy(temp,A[j]);
    string_copy(A[j],A[j-1]);
    string_copy(A[j-1],temp);
}
int string_compare (char *first, char * second){
    ::x++;
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return +1;
if (second[i] == 0) return -1;
if (first[i] < second[i]) return +1;
if (first[i] > second[i]) return -1;
i++;
}
return 0;
}
void string_sort (char A[][MAX], int n) {
    int i, j;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])<0) {
            string_swap(A,j);
            j = j - 1;
            ::y++;
        }
    }
    

}

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

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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 sc=0;
int ss=0;

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

}

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

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

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

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

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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>
#define MAX 15
using namespace std;
int string_compare (char *first, char * second, int &m)
{
m = 0;
while (true){
if (first[m] == 0 && second[m] == 0) return 0;
if (first[m] == 0) return +1;
if (second[m] == 0) return -1;
if (first[m] < second[m]) return +1;
if (first[m] > second[m]) return -1;
m++;
}
return 0;
}
void string_sort (char A[MAX], int n, int &temp, int &m)
{
 temp = 0;
 int i,j;
 for (int i = 0; i < n; i++)
 {
  j = i;
  while ((j>0) && (string_compare (&A[j-1], &A[j], m) < 0)) 
  {
  swap (A[j], A[j-1]);
  j = j - 1;
  temp += 1;
  }
 } 
}
int main()
{
 int n;
 cin>>n;
 int temp;
 int m;
 char A[MAX];
 cin.getline (A, n);
 for (int k = 0; k < n; k++) cin>>A[k];
 string_sort (A, n, temp, m);
 for (int i = n-1; i >= 0; i++)
 {
  cout<<A[i]<<endl;
 }
 cout<<m<<endl<<temp;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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 string_compare(char **c,int n){
for(int i=0;i<n;i++)if(c[i][1]>c[i][1])return 1;
		else if(c[i][1]>c[i][1])return -1;
		else  return 0; 
}
void string_sort(char**c,int n,int&m){
{
    int i, j;

    for (i=1;i < n;i++)
    {
        j = i;

        while (j > 0 && c[j-1][1] >c[j][1])
        {
            swap (*c[j],*c[j-1]);
            j = j - 1;
		m++;
        }
    }
}


}
int main(){
int n,m;
m=0;
cin>>n;
char c[11][11];
for(int i=0;i<n;i++){cin>>*c;}
for(int i=0;i<n;i++){for(int j=0;j!=0;j++){cout<<c[i][j];}}
cout<<n;
cout<<m;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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 maxi=15;
void swap(char *A,char *B)
{
  char temp[maxi];
  for(int i=0;i<maxi;i++)
  {
    temp[i]=A[i];
    A[i]=B[i];
    B[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++;
  }
  return 0;
}
void string_sort(char *A,int n,int count,int swapcnt)
{ 
  count=0;
  swapcnt=0;
  int j;
  for(int i=1;i<n;i++)
  {
   j=i;
   while(j>0&&(string_compare(&A[j-1],&A[j])==1||string_compare(&A[j-1],&A[j])==-1||string_compare(&A[j-1],&A[j])==0))
   {swapcnt++;}
   while(j>0&&string_compare(&A[j-1],&A[j])==1)
   {
      swap(&A[j],&A[j-1]);
      j--;count++;
   }
  }
}
int main(){
int n,count,swapcnt;
cin>>n;
int c=0;
char A[maxi][maxi];
for(int i=0;i<n;i++)
cin.getline(A[c++],maxi);
string_sort(A,n,count);
for(int i=0;i<n;i++)
cout<<A[i]<<endl;
cout<<count<<endl<<swapcnt;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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<cstring>
#define Max 1000
using namespace std;

int string_compare(char A[],char B[]){
    int i=0;
    while(i<11){
     if(A[i]<B[i])return 1;
      else if(A[i]>B[i])return -1;
       else if(A[i]==B[i]){i++;}}
   return 0;} 

void string_sort(char**A,int n,int &l,int &m){
    
   for(int i=1;i<n;i++){
    for(int j=i;j>0;j--){
      if(string_compare(A[j],A[j-1])==-1){
        for(int i=0;i<11;i++){
        char p = A[j][i];
        A[j][i]=A[j-1][i];
        A[j-1][i]=p;
        }l=l+1;
       }
      m=m+1;
    }
   }
}


int main(){
int n,q;
cin>>q;
n=q+1;

char**cha= new char*[n];
  for(int i=0;i<n;i++){
  cha[i]=new char[12];
  }
for(int i=0;i<n;i++){
  cha[i][12]=0;}


for(int i=0;i<n;i++){
cin.getline(cha[i],11);
}
    int l=0,m=0;   
     string_sort(cha,n,l,m);
   for(int i=0;i<n;i++){
    for(int j=0;j<11;j++){
     cout<<cha[i][j];
    }
   cout<<endl;
   }
  cout<<m<<endl<<l<<endl;
return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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;
#define MAX 100

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 a[], char b[]){
int i = 0;
while (true){
if (a[i] == 0 && b[i] == 0) 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++;
}
return 0;
}


void string_sort (char A[][MAX], int n,int& count1,int& count2) 
{
    int i, j;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0)
        {count1+=1;
        if (string_compare(A[j-1],A[j])==-1) { 
            count2+=1;
            char c[MAX];
            string_copy(c,A[j-1]);
            string_copy(A[j-1],A[j]);
            string_copy(A[j],c);
        }
        else{break;}
        j=j-1;}
    }
}

int main()
{
int n,count1=0,count2=0;
cin>>n;

char A[MAX][MAX];

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

string_sort(A,n,count1,count2);

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

cout<<count1<<endl<<count2;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
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 swaps=0;
int comparisions=0;

#define MAX 12

int string_compare(char*a,char*b)
{
	comparisions++;
	int i = 0;
	while (true){
	if (a[i] == 0 && b[i] == 0) 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++;
	}
	return 0;
}

void string_sort (char A[][MAX], int n) 
{
    int i, j;
    for (i=1;i < n;i++){ // for each element of the array
        j = i;
        while (j > 0 && string_compare(A[j],A[j-1])==-1) 
        {
        	swaps++;
        	char temp[MAX];
        	int x;
        	for(x=0;A[j][x]!='\0';x++)
        	{
        		temp[x]=A[j][x];
        	}
        	temp[x]='\0';
        	for(x=0;A[j-1][x]!='\0';x++)
        	{
        		A[j][x]=A[j-1][x];
        	}
        	A[j][x]='\0';
        	for(x=0;temp[x]!='\0';x++)
        	{
        		A[j-1][x]=temp[x];
        	}
        	A[j-1][x]='\0';
            j = j - 1;
        }
    }
}

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	char input[n][MAX];
	for(int i=0;i<n;i++)
	{
		cin>>input[i];
	}
	string_sort(input,n);
	for(int i=n-1;i>=0;i--)
	{
		cout<<input[i]<<endl;
	}
	cout<<comparisions<<endl<<swaps;
	return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
Assigned grade: A