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<bits/stdc++.h>
#define MAX1 15
#define MAX2 12

using namespace std;

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

int* string_sort(char arr_s[][MAX2], int n)
{
	int* ans = new int[2];
	ans[0]=0;
	ans[1]=0;
	for(int i=1; i<n; i++)
	{
		int j=i;
		while(j>0)
		{
			ans[0]++;
			if(string_compare(arr_s[j-1] , arr_s[j]) == 1)
			{
				swap(arr_s[j-1],arr_s[j]);
				ans[1]++;
				j--;
			}
			else
				break;
		}
	}
	return ans;
}

int main()
{
	int n;
	cin >> n;
	char arr_s[MAX1][MAX2];
	for(int i=0; i<n; i++)
		cin >> arr_s[i];
	
	int* ans = string_sort(arr_s, n);
	for(int i=n-1; i>=0; i--)
		cout << arr_s[i]<<endl;
	
	cout << ans[0]<<endl;
	cout << ans[1]<<endl;
	delete ans;
	
	return 0;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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 <simplecpp>
#define maxsize 12

int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
else if (first[i] == 0) return +1;
else if (second[i] == 0) return -1;
else if (first[i] < second[i]) return +1;
else if (first[i] > second[i]) return -1;
i++;
}
return 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 swap(char* e, char* f)
	{
	char temp;
	string_copy(&temp,&e);
	string_copy(&e,&f);
	string_copy(&f,&temp);
	}

main_program{
int n;
cin>>n;
char a[n][maxsize];
for (int i=0;i<n;i++)
	{
	cin>>a[i];
	}
cout<<endl;
for (int i=0;i<n;i++)
	{
	cout<<a[i]<<" ";
	}
swap(&a[0],&a[1]);
cout<<a[0]<<a[1];
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: D
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 12
void copy(char *a,char *b)
{
int i;
for(i=0;i<strlen(b);i++)
{
a[i]=b[i];
}
a[i]=0;
}
int string_compare(char *a,char *b,int &comp)
{
  comp++;
  for(int i=0;i<MAX;i++)
  {
    if(a[i]<b[i]) return 1;
    if(b[i]<a[i]) return -1;
    if(a[i]==0 && b[i]!=0) return 1;
    if(b[i]==0 && a[i]==0) return -1;
  }
return 0;
}
void string_sort(char a[][MAX],int n,int &comp,int &swap)
{
comp=0;
swap=0;
for(int i=0;i<n-1;i++)
{
  int j=i+1;
  while(string_compare(a[j],a[j-1],comp)==1&&j!=0)
  { 
      char temp[MAX]="";
      copy(temp,a[j]);
      copy(a[j],a[j-1]);
      copy(a[j-1],temp);
      j--;
      swap++;
  }
}
}
int main()
{
  int n;
  cin>>n;
  char a[n][MAX];
  for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
  int comp;
  int swap;
  string_sort(a,n,comp,swap);
  for(int i=n-1;i>=0;i--)
  {
    cout<<a[i]<<endl;
  }
  cout<<comp<<endl;
  cout<<swap<<endl;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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;
#define MAX 15
int ccomp = 0; int cswap = 0;

int string_compare(char* first, char* second){
int i=0;
while(true){
	if(first[i]==second[i]) 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 myswap(char* A, char* B){
int i=0;
for(i=0; i<12; i++){
	char temp = A[i];
	A[i] = B[i];
	B[i] = temp;
	}
cswap++;
}

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

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

void cout_strings(char A[MAX][MAX], int n){
	int i=0;
	for(i=0; i<n; i++) {
		cout<<A[i]<<endl;
		}
	}

int main(){
int n; cin>>n;
char A[MAX][MAX];
cin_strings(A,n);
string_sort(A,n);
cout_strings(A,n);
cout<<ccomp<<" "<<cswap<<endl;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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;

void charswap(char* &a,char* &b){
	char* c=&a[0];
	a=&b[0];
	b=&c[0];
}
char** dynchar2D(int m,int n){
	char** A= new char*[m];
	for(int j=0;j<m;j++){
		A[j]= new char[n];
	}
	return A;
}

void charout(char** A,int N){
	for(int j=0;j<N;j++){
		cout<<A[j]<<endl;
	}
}

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 string_sort(char** A,int N,int &comp,int &sww){
	int i=1;
	for(i=1;i<N;i++){
		for(int j=i;j>0;j--){
			if(string_compare(A[i],A[i-1])==1){comp++;break;}
			
				sww++;
				charswap(A[i],A[i-1]);
			
		}
	}
}

int main(){
	int N;cin>>N;int comp=0;int sww=0;
	char** A=dynchar2D(N,20);
	for(int i=0;i<N;i++){
		cin.getline(A[i],20);
	}
	cout<<endl;
	string_sort(A,N,comp,sww);
	charout(A,N);
	cout<<comp<<endl;
	cout<<sww;
}

Grading criterion: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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 <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: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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 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: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
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 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: Sorting algorithm implemented is insertion sort.
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried in somewhat right direction (e.g., different sorting algorithm)
Rating D: totally wrong
Assigned grade: D