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 p=0;
int q=0;


int string_compare(char a[][max],int n1,int n2){
int i=0;
while(true){
if(a[n1][i]==0&&a[n2][i]==0)return 0;
if(a[n1][i]==0)return -1;
if(a[n2][i]==0)return 1;
if(a[n1][i]>a[n2][i])return 1;
if(a[n1][i]<a[n2][i])return -1;
i++;}}


void string_swap(char a[][max],int n1,int n2){
for(int i=0;i<max;i=i+1){swap(a[n1][i],a[n2][i]);}}


void string_sort(char a[][max],int n){
int i,j;
for(i=1;i<n;i=i+1){
j=i;
while(j>0){
int x=string_compare(a,j-1,j);
p=p+1;
if(x==-1){string_swap(a,j-1,j);
j=j-1;
q=q+1;}
else break;}}}


int main(){
int n;
cin>>n;
char a[n][max];
for(int i=0;i<n;i=i+1){cin>>a[i];}
string_sort(a,n);
for(int i=0;i<n;i=i+1){cout<<a[i]<<endl;}
cout<<p<<endl<<q;
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
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>
int string_compare(char*s1,char*s2){
int i=0;
	while(s1[i]==s2[i]&&s1[i]!=0){i++;}
	if(s1[i]<s2[i]){return 1;}
	else if(s2[i]<s1[i]){return -1;}
	else if(s1[i]==s2[i]){return 0;}
}
void stringswap(char*s1,char*s2){
	char s[20];
	for(int i=0;i<20;i++){s[i]=0;}
	for(int i=0;i<20;i++){s[i]=s1[i];}
for(int i=0;i<20;i++){s1[i]=s2[i];}
	for(int i=0;i<20;i++){s2[i]=s[i];}
}
void string_sort(char s[][20],int n,int &l,int &m){
int i,j;
	for(i=1;i<n;i++){
	j=i;
		while(j>0 ){
			l++;
			if(string_compare(s[j-1],s[j])==1){
			stringswap(s[j],s[j-1]);
			m++;
		}j=j-i;}
	}
}
main_program{
	int l=0;int m=0;
	int n;cin>>n;
	
	char s[n][20];
	for(int i=0;i<n;i++){for(int j=0;j<20;j++){s[i][j]=0;}}
	for(int i=0;i<n;i++){cin>>s[i];}
	string_sort(s,n,l,m);
	for(int i=0;i<n;i++){cout<<s[i]<<endl;}
	cout<<l<<endl<<m;
	
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
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;

void swAp (char *&s1, char *&s2, int &swap_count){
	swap_count++;

	char *s = s1;
	s1 = s2;
	s2 = s;
}

int str_compare (char *s1, char *s2, int &comp_count){
	comp_count++;

	int i = 0;
	for (; s1[i] != 0 && s2[i] != 0; i++){
		if (s1[i] != s2[i]){
			break;
		}
	}
	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{
		return -1;
	}
}

void stringSort (char **&s, int n, int &comp_count, int &swap_count){
	for (int i = 0; i < n; i++){
		for (int j = i-1; j >= 0; j--){
			if (str_compare(s[j], s[j+1], comp_count) == -1){
				swAp(s[j], s[j+1], swap_count);
			}
			else{
				break;
			}
		}
	}
}

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

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

	stringSort(s, n, comp_count, swap_count);

	for (int i = 0; i < n; i++){
		cout << s[n-1-i] << "\n";
	}
	cout << comp_count << "\n" << swap_count;

	return 0;
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
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 1000
int f=0;
int g=0;
void input_array(char arr[][MAX], int p){
	for(int k=0; k<p; k++){
			cin>>arr[k];
		
	}	
}
void print_array(char A[][MAX], int p){
	for(int k=p-1; k>=0; k--){
	
			cout<<A[k]<<endl;}
		}
int string_compare (char *first, char * second){
int i = 0; f++;
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 myswap(char A[], char B[]){
	char temp[MAX];
	int i;
for(i=0; A[i]!=0; i++){
	temp[i]=A[i];
}
temp[i]=0;
for(i=0; B[i]!=0; i++){
	A[i]=B[i];
}
A[i]=0;
for(i=0; temp[i]!=0; i++){
	B[i]=temp[i];
}
B[i]=0;
g++;
}

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], A[j-1])== -1) {
            myswap (A[j],A[j-1]);
            j = j - 1;
        }
    }
}
int main(){
	int n;
	cin>>n;
	char A[MAX][MAX];
	input_array(A, n);
	insertion_sort(A, n);
	print_array(A, n);
	cout<<f<<endl<<g;

}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
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>
#include<cmath>
using namespace std;
int string_compare(char*s1,char*s2){
int i=0;
while(1){
if(s1[i]==s2[i]){ 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++;
}
return 0;
}
void string_sort(char**s,int n){
int i,j,sw=0,c=0;
for(i=0;i<n;i++){
j=i;
while(j>0 && string_compare(s[j-1],s[j])==-1){
swap(s[j-1],s[j]);
j--;
sw++;
}
c++;
}
for(i=0;i<n;i++){
cout<<s[n-1-i];
cout<<endl;
}
cout<<c<<endl<<sw;
}
int main(){
int n,i;
cin>>n;
char** s;
s=new char*[n];
for(i=0;i<n;i++){
s[i]=new char[12];
}
for(i=0;i<n;i++){
cin>>s[i];
}
string_sort(s,n);
}

Grading criterion: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
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 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: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
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 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: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
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 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: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
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 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: Sort implemented in function string_sort
Rating A: Fully Correct
Rating B: Almost correct
Rating C: tried in somewhat right direction
Rating D: totally wrong
Assigned grade: C