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 <vector>
  using namespace std;
 int ncmp=0;//comparision counter
int nswap=0;//swapping counter
int string_compare (string first, string second)
{
 int i = 0;
  ncmp++;
   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(vector<string> &v) ///sorting the string array
{
 int n=v.size();//sorting using selection sort
  int i, j;
   for (int i=1;i<n;i++)
   {
    j=i;
    while (j>0 && string_compare(v[j-1], v[j])==1)
     {
      nswap++;
       string temp=v[j];
       v[j]=v[j-1];
       v[j-1]=temp;
      j=j-1;
    }
 }
 for (int i=0;i<n/2;i++) //reverse for decending order
  {
   string temp=v[i];
   v[i]=v[n-i-1];
  v[n-i-1]=temp;
 }
}

int main()
 {
  int n;
   cin>>n;
    string word;
     vector<string> v;
      for (int i=1;i<=n;i++)//taking the input
       {
        cin>>word;
       v.push_back(word);
      }
     string_sort(v);
    for (auto it: v)//printing the sorted array
   {cout<<it<<" "<<endl;}
  cout<<ncmp<<endl;
 cout<<nswap;
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: 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>
#define max 12
using namespace std;
void myswap(char* a, char* b)
{
char temp[max];
for(int i=0;i<max;i++)
{
temp[i]=a[i];
a[i]=b[i];
b[i]=temp[i];
}
}
int string_compare(char a[max], char b[max])
{
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
i++;
}
if(a[i]=='\0' && b[i]!='\0')
return 1;
if(a[i]!='\0' && b[i]=='\0')
return -1;
}
void string_sort(char a[max][max], int n)
{
int i,j;
for(i=1;i<n;i++)
j=i;
int k=string_compare(a[j],a[j-1]);
while(j>0 && k==1)
{
myswap(&a[j],&a[j-1]);
j=j-1;
}
}
int main()
{
int n;
cin>>n;
char a[n][max];
for(int i=0;i<n;i++)
{
	for(int j=0;j<max-1;j++)
	{
	cin>>a[i][j];
	}
}
string_sort(a,n);
for(int i=0;i<n;i++)
{
	for(int j=0;j<max-1;j++)
	{
	cout<<a[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<iostream>
using namespace std;
const int MAX=8;

void
compute_matrixtranspose_matrix_product(
int A [][MAX],int m,int n,int,int ATA [MAX])
{ // compute AT*A
 for (int row 1=0;row 1<n;
 row 1++){
 for (int col 1=0;col 1<n;
 col 1++){
 ATA[row 1][col 1]=0;
 for (int e=0;e<m;e++)
{
 ATA[row 1][col 1]+=A[e]
 [row 1]*A[e][col 1];
    }
   }
 } 
return;
}
int main(){
int m,n;
cin>>m>>n;
//m,n<=8
int A[MAX][MAX];
for (int i=0;i<m;i++){
for (int j=0;j<n;j++){
cin >>A[i][j];
  }
 }
// compute A*A
Iint ATA[MAX][MAX];
compute_matrixtranspose_matrix_product(A,m,n,ATA);
// ATA is n*n matrix...
for (int i=0; i<n,i++){
for (int j=0; j<n,j++){
cout << ATA [i][j]<<"";
} 
cout<<endl;
}
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: 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
int swaps=0;
int compare=0;
int string_compare (char *first, char * second){
	compare++;
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[][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]);
            j = j - 1;
			swaps++;
        }
    }
}

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>-1;i--){
		cout<<A[i]<<endl;
	}
	cout<<compare<<endl<<swaps;
	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>
#define MAX 100
using namespace std;
void input(char *&A,int n)
{
for(int i=0;i<n;i++)
{
cin >> A[i];
}
}
int string_compare(char *f, char *s)
{
int i=0;
while (true)
{
if (f[i]==0 && s[i]==0) return 0;
if (f[i]==0) return -1;
if (s[i]==0) return +1;
if (f[i]<s[i]) return -1;
if (f[i]>s[i]) return +1;
i++;
}
return 0;
}
void string_sort(char A[][MAX], int n)
{
int i,j,k=0;
char t[MAX];
for(k=0;A[j]!=0;k++)
{t[k]=A[i][j]
for(i=1;i<n;i++)
{
j=i;
while (j>0 && A[j-1]>A[j])
{
t=A[j-1];
A[j-1]=A[j];
A[j]=t;
j=j-1;
}
}
}
void string_print(char A[][MAX], int n)
{
for(int i=n-1;i>=0;i--)
{
cout << A[i] << '\n';
}
}
int main ()
{
int n;
cin >> n;
char A[n][MAX];
input(char A[n][MAX], int n);
string_sort(char A[n][MAX], int n);
string_print(char A[n][MAX], int 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>
using namespace std;
#define MAX 12
int strcompare=0;
int strswap=0;
void input(char s[][MAX],int n){
        for(int i=0;i<n;i++){
		cin>>s[i];
                /*for(int j=0;j<MAX;j++){
                        cin>>s[i][j];
                        }*/
                }
        }
int string_compare(char a[],char b[]){
	strcompare++;
	int na=0;int nb=0;
	while(a[na]!=0 && b[nb]!=0 && na<MAX && na<MAX){
		if(a[na]<b[nb]){return 1;}
		else if(a[na]>b[nb]){return -1;}
		else{na++;nb++;}
		}
	if(a[na]){return -1;}
	else if(b[nb]){return 1;}
	else{return 0;}
	}
void myswap(char s[][MAX],int i,int j){
	for(int x=0;x<MAX;x++){
		char temp=s[i][x];
		s[i][x]=s[j][x];
		s[j][x]=temp;
		}
	strswap++;
	}
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-1],a[j])==-1){
            		myswap(a,j,j-1);
            		j=j-1;
			}
    		}
	}
void output(char s[][MAX],int n){
	for(int i=n-1;i>=0;i--){
		int j=0;
		while(s[i][j] && j<MAX){
			cout<<s[i][j++];
			}
		cout<<endl;
		}
	}
int main(){
int n;cin>>n;
char s[n][MAX];
input(s,n);
//for(int i=0;i<MAX;i++){if(!s[0][i])break;cout<<s[0][i];}
string_sort(s,n);
output(s,n);
cout<<strcompare<<endl<<strswap;
}

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>
#define MAX 12
using namespace std;

int comparisons=0, swaps=0;

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

void string_swap(char*& str1, char*& str2){ 
	char* temp = str1; 
	str1 = str2; 
	str2 = temp; 
}

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

void print_reversematrix(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];}
	
	string_sort(A,n);
	print_reversematrix(A,n);
	cout<< comparisons <<'\n' << 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>
#define MAX 11
#include<cstdlib>
using namespace std;
int string_compare(char s1[], char s2[]){
int i=0;
while (true){
if (s1[i] == '\0' && s2[i] == '\0') return 0;
else if (s1[i]== '\0') return 1;
else if (s2[i] == '\0') return -1;
else if (s1[i] > s2[i]) return -1;
else if (s1[i] < s2[i]) return 1;
i++;
}
return 0;
} 
void string_sort(char s[][MAX], int n, int &k, int&l){
int i, j;
for (i=1; i < n; i++){
j = i;
while (j > 0){
if (string_compare(s[j], s[j-1]) == 1) {
swap(s[j],s[j-1]);
k++; 
l++;
}
else {
k++;
break;
}
j--;
}
}
}
int main(){
int n;
cin >> n;
char s[n][MAX];
for (int a=0; a < n; a++){
cin >> s[a];
}
int k,l;
k = l=0;
string_sort(s,n,k,l);
for (int a=n-1; a > -1; a--){
cout << s[a] << endl;
}
cout << k << endl << l;
}

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