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;
void copy(char*a,char*b){int i=0;
while(a[i] != '\0'){b[i] =a[i];i++;}
b[i]='\0';
}

void swap(char*a,char*b){
char temp[12];
copy(b,temp);
copy(a,b);
copy(temp,a);
}

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++;}
}
void sort(char a[][12],int n,int &s,int &c)
{
for(int i=1;i<n;i++){
int j =i;
while(j>0 && (string_compare(a[j-1],a[j]) > 0))
{
swap(a[j],a[j-1]);s++;c++;
j--;}
if(j>0){c++;}
}
}

int main(){
int n,c=0,s=0;
cin>>n;
char a[n][12];
for(int i=0;i<n;i++){cin>>a[i];}
sort(a,n,s,c);
for(int i=n-1;i>=0;i--){cout<<a[i]<<endl;}
cout<<c<<endl;
cout<<s;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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 20
using namespace std;
int string_compare(char* f,char* s,int& comp)
{int i=0;comp++;
while(1)
{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 words[][MAX],int n,int& swapcount,int& comp)
{for(int i=1;i<n;i++)
 {int j=i;
 while(j>0 && string_compare(words[j],words[j-1],comp)==1)
 {swap(words[j],words[j-1]);
 swapcount++;
 j=j-1;}
}
//print elements in reverse order
for(int i=0;i<n;i++){ cout << words[i] << endl;}
}
int main()
{char words[MAX][MAX];
 int n,swapcount=0,comp=0;cin >> n;
 for(int i=0;i<n;i++) cin >> words[i];
 string_sort(words,n,swapcount,comp);
 cout << comp << endl;
cout << swapcount;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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>
#define MAX 100
using namespace std;
int string_compare(int n,char A[MAX][MAX]){

if(A[n][0]>A[n-1][0])return -1;
else if(A[n][0]<A[n-1][0])return 1;
else if(A[n][0]==A[n][0])return 0;


}
void string_sort(char A[MAX][MAX],int n){
int i,j,k=0;
for(i=1;i<n;i++){
j=i;

int b=string_compare(j,A);
if(b==-1){
while(j>0){
int temp=A[j][0];
A[j][0]=A[j-1][0];
A[j-1][0]=temp;
k++;
j=j-1;
}
}
}
cout<<k;
}

int main(){
int n;
cin>>n;
char A[MAX][MAX];
char B[11];
A[0][0]=1;
for(int i=0;i<n;i++){
cin>>B;
A[i][0]=*B;
}
string_sort(A,n);
for(int i=0;i<n;i++){
cout<<A[i][0]<<endl;
}

}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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>
using namespace std;
#define M 12
void swap(char*&first,char *&second){
char*temp;
temp=first;first=second;second=temp;
}
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 sam [][M],int n,int&k,int&t){
int i,j;
for(i=1;i<n;i++){

for(j=i;j>0;j--){
int y=string_compare(sam[j],sam[j-1]);k++;
if(y==-1){swap(sam[j],sam[j-1]);t++;}
else continue;
}
}
}
int main(){
int n,count=0,k=0,t=0;
cin>>n;
char strings[n][M];
while(cin.getline(strings[count++],12));
string_sort(strings,n,k,t);
for (int i=0; i<n; i++)cout<<"\t" <<  strings[i] << endl;
cout<<k<<endl;
cout<<t;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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;
int c1=0, c2=0;

void myswap(char a[], char b[])
{++c2;
char c[12];
int i=0, j=0, k=0;
while(a[i]!=0){c[i]=a[i];++i;} c[i]=0;
while (b[j]!=0) {a[j]=b[j]; ++j;} a[j]=0;
while (c[k]!=0) {b[k]=c[k]; ++k;} b[k]=0;
return;
}

int string_compare(char a[], char b[])
{++c1;
for (int i=0; ; ++i)
{if (a[i]==0 && b[i]==0) return 0;
if (a[i]<b[i] || a[i]==0) return 1;
if (a[i]>b[i] || b[i]==0) return (-1);
}
}

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

int main()
{int n; cin>>n;
char a[n][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]<<'\n';
cout<<c1<<'\n'<<c2;
return 0;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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;

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 arrswap(char a[], char b[], int &no_swaps){
	no_swaps++;
	char temp[100];
	string_copy(temp,a);
	string_copy(a,b);
	string_copy(b,temp);
}

void arrinput(char a[][100],int n){
	for(int i = 0; i < n; i++) cin >>  a[i];
}

void arr_rev_print(char a[][100],int n){
	for(int i = n-1; i >= 0; i--) cout << a[i] << endl;
}

int string_compare(char a[], char b[],int &no_comp){
	no_comp++;
	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[][100],int n, int &no_swaps, int &no_comp){
	int i, j;
    	for (i=0;i<n ;i++){
       	 	j = i;
        	while (j > 0 && string_compare(a[j-1],a[j],no_comp)==1){
       			arrswap(a[j-1],a[j],no_swaps);
            		j--;
        	}
    	}
}

int main(){
	int n;
	cin >> n;
	char a[n][100];
	int no_swaps = 0;
	int no_comp = 0;
	arrinput(a,n);
	string_sort(a,n,no_swaps,no_comp);
	arr_rev_print(a,n);
	cout << no_comp << endl << no_swaps;
	return 0;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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 11
#define box 100
using namespace std;
void swap_string(char first[box],char second[box]){
char temp[box];
int i;
for ( i=0;first[i]!=0;i++){
    temp[i]=first[i];}
temp[i]=first[i];
 int j;
for (j=0;second[j]!=0;j++){
     first[j]=second[j];}
first[j]=second[j];
int k;
for ( k=0;temp[k]!=0;k++){
         second[k]=temp[k];}
second[k]=temp[k];
}

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 C[box][11],int n){
int c=0;int  s=0;
int i,j;
for( i=1;i<n;i++){
    j=i;int a=string_compare(C[j-1],C[j]);
    while (j>0&&a==+1){
    swap_string(C[j-1],C[j]);
j=j-1;
s++;
}
       c++;
 }
for (int i=0;i<n;i++){
cout<<C[n-i-1]<<endl;}

cout<<c+1<<endl;
cout<<s;
}
int main(){
int n,c,s;
cin>>n;
char C[n][11];
for (int i=0;i<n+1;i++){
cin.getline(C[i],11);}
string_sort(C,n);


}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or 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>
const int MAX=12;
void swap(char *a,char *b){
char temp=*a;*a=*b;*b=temp;
}
void input(int n,char A[][MAX]){
for(int i=0;i<n+1;i++){
cin>>A[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 &k) {
    int i, j;
    for (i=1;i < n+1;i++){
        j = i;
        while (j > 0 && string_compare(A[j-1],A[j])==-1) {
        for(int p=0;p<MAX;p++){
            swap (&A[j][p],&A[j-1][p]);}
            k++;
            j = j - 1;
        }
    }
}

main_program{
int n;
cin>>n;
int k=0;
char A[MAX][MAX];
for(int i=0;i<MAX;i++){
for(int j=0;j<MAX;j++){
A[i][j]=0;
}
}
input(n,A);
string_sort(A,n,k);
for(int i=n;i>=0;i--){
cout<<A[i]<<endl;
}
cout<<n<<endl<<k-n;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A