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 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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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 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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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>
#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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A