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;
#define MAX 30
int count_compare=0, count_swap=0;
int string_compare(char *s, char *t)
{
count_compare++;
int i=0;
while(true)
{
if(s[i]==0&&t[i]==0) return 0;
if(s[i]==0) return 1;
if(t[i]==0) return -1;
if(s[i]<t[i]) return 1;
if(t[i]<s[i]) return -1;
i++;
}
return 0;
}
void string_sort(char s[][MAX], int n)
{
int i, j;
for(i=1; i<n; i++)
{
j=i;
while(j>0&&(string_compare(s[j], s[j-1])==1))
{
count_swap++;
char temp[MAX];
for(int i=0; i<MAX; i++)
{
temp[i]=s[j][i]; s[j][i]=s[j-1][i]; s[j-1][i]=temp[i];
}
j--;
}
}
}
int main()
{
int n; cin>>n;
char s[n][MAX];
for(int i=0; i<n; i++)
for(int j=0; j<MAX; j++)
s[i][j]=0;
for(int i=0; i<n; i++)
cin>>s[i];
string_sort(s, n);
for(int i=n-1; i>=0; i--)
cout<<s[i]<<endl;
cout<<count_compare<<endl<<count_swap;
}

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;

const int maxn = 15;

int times_string_compare = 0, times_string_swap = 0;


int string_len(char a[]){
	int i=0;
	while(a[i] != 0)i++;
	return i;
}

void string_swap(char a[], char b[]){
	times_string_swap++;
	for(int i=0; i<=max(string_len(a), string_len(b)); i++)swap(a[i], b[i]);
}


int string_compare(char a[], char b[]){
	times_string_compare++;

	int i = 0;
	while(a[i]==b[i] && a[i] != 0)i++;
	
	if(a[i] == 0 && b[i] == 0)return 0;
	else if(a[i] < b[i])return 1;
	else return -1;

}


void string_sort(char arr[][maxn], int n){

	for(int i = 1; i < n; i++){
		for(int j = i; j > 0 && string_compare(arr[j], arr[j-1]) == 1; j--){
			string_swap(arr[j], arr[j-1]);
		}
	}
}

int main(){
	
	int n; cin>>n;

	char arr[n][maxn];
	for(int i=0; i<n; i++)cin>>arr[i];

	string_sort(arr, n);

	for(int i=n-1; i>=0; i--)cout<<arr[i]<<"\n";	
	cout<<times_string_compare<<"\n";
	cout<<times_string_swap<<"\n";

	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;
int const MAX=15;

int ctswap=0; 
int ctcompare=0;

void string_swap(char A[MAX][MAX], int x1, int x2) {
ctswap++;
	
	char temp[MAX];
	for (int i=0; i<12; i++) temp[i]=A[x1][i];
	for (int i=0; i<12; i++) A[x1][i]=A[x2][i];
	for (int i=0; i<12; i++) A[x2][i]=temp[i];
}


int string_compare (char A[MAX][MAX], int x1, int x2) {
ctcompare++;
int i = 0;
while (true) {
if (A[x1][i] == 0 && A[x2][i] == 0) return 0;
if (A[x1][i] == 0) return -1;
if (A[x2][i] == 0) return +1;
if (A[x1][i] < A[x2][i]) return (-1);
if (A[x1][i] > A[x2][i]) return (+1);
i++;
}
return 0;
}

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

int main(){
char A[MAX][MAX];
char y[10];
int n; 
cin>>n;
cin.getline(y,10);
for (int i=0; i<n; i++) {
 cin.getline(A[i],12);
}
string_sort(A,n);


for(int i=0; i<n; i++) {
cout << A[i] << endl;
}
cout << ctcompare <<endl; 
cout << ctswap;
}

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 MAX 15
void string_compare (char *first, char * second){
int i = 0;int n;cin>>n;int *& x[n];
while (true){
if (first[i] == 0 && second[i] == 0)  x[i]=0;
if (first[i] == 0) x[i]=1;
if (second[i] == 0) x[i]=1;
if (first[i] < second[i]) x[i]=-1;
if (first[i] > second[i]) x[i]=1;
i++;
}
}
void string_sort(char **S,int n){
for(int i=0;i<n;i++){for(int j=0;j<n;j++){
if (j>=i){
string_compare(S[i],S[j]);		
}}
					}	
for (int i=0;i<n;i++){int j=i;while (j>0 && x[i]==1){
char *temp=S[j-1];S[j-1]=S[j];S[j]=temp;j=j-1;		
}}	
	
}
int main(){
int n;cin>>n;
char **S=new char* [n];
for(int i=0;i<n;i++){
S[i]=new char[MAX]; 					
cin.getline(S[i],MAX);	
}
string_sort(S,n);
for(int i=0;i<n;i++){cout<<S[i]<<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 maxa 15

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

void myswap(char &a1,char &a2){
char temp;
temp=a2;
a2=a1;
a1=temp;
}

void string_sort(char str[][maxa],int n,int &n1,int &n2){
int i, j;
    for (i=2;i<n+1;i++){ 
    j = i;
        while(j>0 && (string_compare(str[j-1],str[j],n1)==-1)) { 
            for(int k=0;k<maxa;k++){
            myswap(str[j][k],str[j-1][k]);
            }
        n2++;
        j--;
        }
    }
}

void printout(char str[][maxa],int n){
for(int i=1;i<n+1;i++){cout<<str[i]<<endl;}
}

int main(void){
int n;
cin>>n;
int n1=0,n2=0;
char str[n+1][maxa];
	for(int i=0;i<n+1;i++){
		for(int j=0;j<maxa;j++){str[i][j]=0;}
	}
	for(int i=0;i<n+1;i++){cin.getline(str[i],maxa);}
string_sort(str,n,n1,n2);
printout(str,n);
cout<<n1<<endl<<n2;
}

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 100
using namespace std;
void strcpy(char *dest,  char* source) {
        int i;
        for(i=0;source[i]!=0;i++){
                dest[i] = source[i];
        }
        dest[i] = source[i];
}
void swap2(char a[],char b[]){
char c[MAX];
strcpy(c,b);
strcpy(b,a);
strcpy(a,c);
}
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 insertion_sort (char A[][MAX], int n,int &p,int &k) {
    int i, j;
    for (i=1;i < n;i++){
        j = i;int t=0;
        while (j > 0 && string_compare(A[j],A[j-1])==-1) { 
            swap2(A[j],A[j-1]);
		k++;
		p++;	
		t++;
            j = j - 1;
        }
       p++;
    }
}
int main(){
int n,p,k;
cin>>n;
p=k=0;
char C[MAX][MAX];
for(int i=0;i<n;i++){
cin>>C[i];
}
insertion_sort(C,n,p,k);
for(int i=0;i<n;i++){
cout<<C[n-1-i]<<endl;
}
cout<<p<<" "<<k;
}

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 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: 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<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: 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