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 swaps=0;
int compare=0;
void input(char a[][max],int n)
{
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void output(char a[][max],int n)
{
for(int i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}
void swapss(char a[],char b[])
{
swaps++;
char temp[max];
int i=0;
while(a[i]!=0)
{
temp[i]=a[i];
i++;
}
temp[i]=a[i];
i=0;
while(b[i]!=0)
{
a[i]=b[i];
i++;
}
a[i]=b[i];
i=0;
while(temp[i]!=0)
{
b[i]=temp[i];
i++;

b[i]=temp[i];
}
}
int string_compare(char a[],char b[])
{compare++;
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 reverse(char a[][max],int n)
{
for (int i=0;i<n/2;i++)
{
swap(a[i],a[n-1-i]);
}
}

void string_sort(char a[][max],int n)
{
int i,j;
for(int i=1;i<n;i++){

j=i;
	while(j>0&&string_compare(a[j-1],a[j])==-1)
	{
	swapss(a[j-1],a[j]);
	j--;
	}
	}
	/*int j=0;
	while(j<i&&string_compare(a[i],a[j])==-1)
	{
	swapss(a[i],a[j]);j++;
	}}*/
	
}

int main()
{
int n;
cin>>n;
char a[n][max];
input(a,n);
string_sort(a,n);
reverse(a,n);
output(a,n);
cout<<compare<<endl<<swaps;

}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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>
#include<cmath>
#include<cstring>
using namespace std;
#define mx 12

int string_compare(char *a,char*b,int &w){
	int i=0;w++;
	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 swap2(char * a,char *b){
	char temp[12];
   strcpy(temp,a);strcpy(a,b);strcpy(b,temp);

}

void string_sort(char a[][mx],int n, int &t,int &w){
	 int i, j;
    for (i=1;i < n;i++){
        j = i;
        while (j > 0 && string_compare(a[j-1], a[j],w)==1) { 
            swap2 (a[j],a[j-1]);t++;
            j = j - 1;
                                                         }
                         }
                                       }
int main(){
	int n,t=0,w=0;
	cin>>n;
	char a[n][mx];
	for(int i=0;i<n;i++) cin>>a[i];
	string_sort(a,n,t,w);
	for(int i=n-1;i>=0;i--) cout<<a[i]<<endl;
	cout<<w<<endl<<t;
}
/*
void swap2(char * a,char *b){
	char temp[12];
   strcpy(temp,a);strcpy(a,b);strcpy(b,temp);

}
int main(){
	char a[]="adfg";char b[]="xcfe";
	swap2(a,b);
	cout<<b; // this was just rough work
}*/

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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;

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


void string_sort(char**s, int n){
	int compares = 1, swaps = 0;
	int i, j;
	for(int i = 1; i<n; i++){
		j = i;
		compares++;
		while(j>0 && string_compare(s[j-1], s[j]) == -1){
 			char * temp = s[j];
 			s[j] = s[j-1];
 			s[j-1] = temp;
 			swaps++;
			j = j-1;
		}
	}	
	for(int i = n-1; i>=0; i--){
		cout << s[i] << "\n";
	}
	cout << compares << "\n" << swaps;
}

int main(){
	int n; cin >> n;
	char ** s =  new char*[n];
	for(int i = 0; i<n; i++){
		char *t = new char[12];
		cin >> t;
		s[i] = t;
	}
	string_sort(s, n);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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>
#include<string>
using namespace std;
# define MAX 100

int compare=0;
int sort=0;

int string_compare (char A[], char B[]){
compare = compare + 1;
if (A>B) return 1;
else if (A<B) return -1;
else 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]);


if (string_compare==1){
	sort +=sort;
  swap (&A[j],&A[j-1]);
            j = j - 1;
        }
    }}
}

int main(){
int n;
cin>>n;
char string[8];

char strings[n][8];

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



}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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<simplecpp>
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 stringreverse(char *s1, char* s2){
char s[100];
//for(int i=0;i<100;i++){
//s[i]="0";
//}
for(int i=0;i<100;i++){
s[i]=s1[i];s1[i]=s2[i];s2[i]=s[i];
}}
void stringsort(char A[][100],int n,int &l,int&m){
    int i, j;l=-1;m=0;
    for (i=1;i < n;i++){ 
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])==-1) { 
	
            stringreverse (A[j-1],A[j]);m++;
            j = j - 1;
        }l++;
    }

}

main_program{
int n,l,m;

cin>>n;
char A[n][100];
//for(int i=0;i<n;i++){
//(int j=0;j<n;j++){A[i][j]="0";}
//}
for(int i=0;i<n;i++){cin>>A[i];}
stringsort(A,n,l,m);
for(int i=0;i<n;i++){cout<<A[i]<<endl;}
cout<<m<<endl;
cout<<l<<endl;



}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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;
int string_compare(char* p,char* q)
{
int pi=0;
while(p[pi]!=0 && q[pi]!=0)
	{
	  if(p[pi]>q[pi]){return -1;}
	  if(p[pi]<q[pi]){return 1;}
	  pi++;  }
	  if(p[pi]==0 && q[pi]==0){return 0;}
	  if(p[pi]==0){return 1;}
	  if(q[pi]==0){return -1;}  }


int string_swap(char** A,int n,int& p)
	{int swapi=0;
	  for(int i=1;i<n;i++)
		{
		  for(int j=i-1;j>=0;j--){p++; if(string_compare(A[j],A[j+1])==-1)
						{char* temp=A[j];swapi++;
						 A[j]=A[j+1]; A[j+1]=temp;}
					   else{break;}}}
		return swapi; }
int main(){
int n;
cin>>n;
char** A;
A= new char*[n];
for(int i=0;i<n;i++){A[i]=new char[12]; cin>>A[i];}
int p=0;
int swapi=string_swap(A,n,p);
for(int i=0;i<n;i++){cout<<A[n-i-1]<<endl;}
cout<<p<<endl<<swapi;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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;
int compareCount=0;int swapCount=0;
int string_compare (char *first, char * second){
	int i = 0;compareCount++;
	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[15][12],int n){
	for (int i=1;i<n;i++){
		char obj[12]=a[i];int j=i-1;
		while(string_compare(obj,a[j])==+1 && j>=0){
			a[j+1]=a[j];j--;swapCount++;
		}a[j+1]=obj;
	}
}
*/	
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][0]<<endl;
	}cout<<compareCount<<endl<<swapCount;
	return 0;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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>
#include<cstring>
using namespace std;
int cmp=0;
int sw=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(second[i]<first[i]) return 1;
      i++;
     }
     return 0;}

void string_sort(char x[100][100],int n){
        int i,j;
        char c[100];
        for (i=1;i<n;i++){
        j=i;
        int p=string_compare(x[j-1],x[j]); cmp++;
        while(j>0&& string_compare(x[j-1],x[j])==-1){ 
               sw++;
               strcpy(c,x[j]);
               strcpy(x[j],x[j-1]);
               strcpy(x[j-1],c);
          j--;
        }
    }
}

int main(){
        char x[100][100];
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
          cin>>x[i];
        }
        string_sort(x,n);
        for(int i=0;i<n;i++){
         cout<<x[i]<<endl;}
        cout<<cmp+1<<endl<<sw;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C