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;
#define MAX 100
int string_compare (char *first, char * second){
//a++;
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 swap(char A[][MAX],int n1, int n2){
	for(int i=0;i<11;i++){
		char temp=A[n1][i];
		A[n1][i]=A[n2][i];
		A[n2][i]=temp;
	}
}
void insertion_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 && A[j-1][0] < A[j][0]) { // find the location to insert it to
	 // maintain a sorted subarray of i elements
            swap (A,j,j-1);
            j = j - 1;
        }
    }
}
void print2Darray (char A[][MAX], int n){
int i,j;
for(i=0;i<n;i++){
		for(j=0;j<11;j++){
			cout << A[i][j];
		}
		cout << endl;
}
}
int main(){
int i,j,n; cin>>n;
char A[MAX][MAX];
for(i=0;i<n;i++){
	char x[100]; cin.getline(x,11);
		for(j=0;j<11;j++){
			if(x[j]==0) break;
			A[i][j]=x[j];
		}
}
print2Darray(A,n);
}

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 a=0,b=0;
int string_compare (char *first, char * second){
int i = 0;
while (true){a++;
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_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_sort(char array[][12],int n){
int i,j;
for(i=1;i<n;i++){
j=i;
while(j>0 && string_compare(array[j-1],array[j])==1){
char m[12],n[12];
string_copy(m,array[j-1]);string_copy(n,array[j]);
string_copy(array[j-1],n);string_copy(array[j],m);
j=j-1;b++;


}
}
}

int main(){
int n;cin>>n;
char array[n][12];
for(int i=0;i<n;i++){cin>>array[i];}
string_sort(array,n);
for(int i=0;i<n;i++){
cout<<array[i]<<endl;
}

cout<<a<<endl;
cout<<b<<endl;


}

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 main()
{int n;
cin>>n;
char name[n-1][20];
int count=0;
while (cin.getline(name[count++], 20));
}

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<cstring>
#include<cmath>
#include<iostream>
using namespace std;

int string_compare(char a[],char b[])
{
int i=0;
while(true){
if(a[i]<b[i])return 1;
if(a[i]>b[i])return -1;
if(a[i]==b[i])return 0;
if(a[i]==0)return 1;
if(b[i]==0)return -1;
i++;

}
return 0;
}

//void swapc(char a[],char b[])
//{
//char temp[100];
//for(int i=0;i<15;i++)
//{
//temp[i]=a[i];
//a[i]=b[i];
//b[i]=temp[i];
//}
//}




int string_sort(char a[][12],int n)
{
int m=0,c=0;
	
	
	int i,j;
	for (i=1;i < n;i++){ 
        j = i;
        int b=string_compare(a[j-1],a[j]);
        if(b!=20){c++;}
        while (j > 0 && b==1) { 
	             swap (a[j],a[j-1]);
            j = j - 1;
        }
    }

	
	
	
	
	return c;
	
}


int main()
{
int n;cin>>n;
char A[n][12];
for(int i=0;i<n;i++){
cin>>A[i];
}
int c=string_sort(A,n);
	for(int i=0;i<n;i++){
	cout<<A[i]<<endl;
}
cout<<endl<<c;
}

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 *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;
}


int main()
{
int n;
cin>>n;
char A[n];
char B[n];
cin>>A;
cin>>B;
cout<<string_compare(A,B);


}

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 12


int string_compare (char arr1[MAX], char arr2[MAX],int* a){
    *(a)+=1;
    for(int i=0;i<MAX;i++){
        if (arr1[i] > arr2[i]) return -1;
        if (arr2[i] > arr1[i]) return 1;
    }
    return 0;
}

void swap (char arr1[MAX], char arr2[MAX],int* b)
{   
    *(b)+=1;
    char temp [MAX];
    for (int i=0;i<MAX;i++){
        temp[i]=*(arr1+i);
    }


    for (int i=0;i<MAX;i++){
        *(arr1+i)=*(arr2+i);
    }
    
    for (int i=0;i<MAX;i++){
        *(arr2+i)=temp[i];
    }
    
}



void insertion_sort (char Arr [][MAX], int n, int* a,int* b)
{
    int i,j;

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

        while (j > 0 && string_compare(Arr[j-1],Arr[j],a)==1)
        {
            swap (Arr[j],Arr[j-1],b);
            j = j - 1;
        }
    }
}








int main(){
int n;
cin>>n;

char twoDarray [n][MAX];
int a=0,b=0;

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

insertion_sort (twoDarray,n,&a,&b);

for (int i=0;i<n;i++){
    cout<<twoDarray[i]<<endl;
}
cout<<a<<endl<<b;
}

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