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;

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_copy (char *dest, const char* source) {
	int i;
	for(i=0;source[i]!= 0;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}

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


int main(){
    int n;
    cin>>n;
    char a[n][12];
    for(int i=0; i<n; i++) cin>>a[i];
    string_sort(a, 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: 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;
#include <cstring>
int count =0,hue=0;
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_copy (char *dest,  char* source) {
	int i;
	for(i=0;source[i]!= 0;i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}
void string_sort (char **a,int n){
	int j=1;
    for (int i=1;i < n;i++){ 
        j = i;
        while (j > 0 && string_compare(a[j-1],a[j])==1 ) { 
            char temp[12];string_copy(temp,a[j]);
			string_copy(a[j],a[j-1]);
			string_copy(a[j-1],temp);
            j = j - 1;count++;hue++;
        }
	if(j!=0) count++;
    }
	
}

int main(){
	int n;cin>>n;
	char **a=new char *[n];
	for(int i=0;i<n;i++){
		a[i] =  new char [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]<<endl;
	}cout<<count<<endl<<hue;
	
	
	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>
#include<cstring>
using namespace std;
void swap(int *a,int *b){
        int temp=*a;
        *a=*b;
        *b=temp;
}
int string_compare (char *A, char *B){
int i = 0;
while (true){
if (A[i] < B[i]) return -1;
if (A[i] > B[i]) return +1;
        else return 0;
i++;
}
return 0;
}
int numswap=0;
int numcomp=0;
void insertion_sort (char *A, int n) {
    int i, j;
    for (i=1;i < n;i++){ 
                numcomp++;
        j = i;
        while (j > 0 && string_compare(A[j-1] ,A[j])==1){ 
            swap(&A[j],&A[j-1]);
            j = j - 1;
                        numswap++;
        }
    }
}

int main(){
        char *A;
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
                cin>>A[i];}
        insertion_sort(A,n);
        for(int j=0;j<n;j++){
                cout<<A[j];}
        cout<<numcomp<<" "<<numswap;
}

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;
#define MAX 12

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 string_sort(char arr[][MAX], int n, int* ctrswap, int* ctrcmp)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
int cmp=string_compare(arr[j],arr[j+1]);
ctrcmp++;
if(cmp==-1)
{
char a[MAX];
strcpy(a,arr[j]);
strcpy(arr[j],arr[j+1]);
strcpy(arr[j+1],a);
ctrswap++;}
}
}
}

int main()
{
int n,ctrswap=0,ctrcmp=0;
cin>>n;
char arr[n][MAX];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
string_sort(arr,n,&ctrswap,&ctrcmp);
for(int i=n-1;i>=0;i--)
{cout<<arr[i]<<endl;}
cout<<ctrcmp<<endl;
cout<<ctrswap;
}

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>
#include<cmath>
#include<string.h>
using namespace std;

#define max 12

int string_compare(char *a,char *b,int &x)
{
int i=0; x=x+1;
while(a[i]==b[i] && i<max && a[i]!=0) i++;
if(a[i]<b[i]) return 1;
else if(a[i]>b[i]) return -1;
else return 0;
}

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

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

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;
int string_compare(char w[][15],int j){
int a,b,n1,n2;n1=n2=a=b=0;
while(w[j][a]!='\0')a++;
while(w[j+1][b]!='\0')b++;
while(n1<a && n2<b){
if(w[j][n1]>w[j+1][n2])return -1;
else if(w[j][n1]<w[j+1][n2]) return 1;
else if(w[j][n1]==w[j+1][n2]){n1++;n2++;}
if(n1==a&& n2==b)return 0;
else if (n1==a) return 1;
else if(n2==b) return -1;
}
}
void myswap(char w[][15],int j){
int a,b;a=b=0;
while(w[j][a]!='\0')a++;
while(w[j+1][b]!='\0')b++;
char temp[a];
for(int i=0;i<=a;i++)temp[i]=w[j][i];
for(int i=0;i<=b;i++)w[j][i]=w[j+1][i];
for(int i=0;i<=a;i++)w[j+1][i]=temp[i];
}
void string_sort(char w[][15],int n){
int swap,compare;
swap=compare=0;
for(int i=1;i<n;i++){
for(int j=i-1;j>=0;j--){
 int k=string_compare(w,j);compare++;//compares w[j],w[j+1]
  if(k==1){myswap(w,j);swap++;}//swaps w[j] ,w[j+1]:
  else  break;
  }
 }
for(int i=0;i<n;i++){cout<<w[i]<<endl;}
cout<<compare<<endl<<swap;
}
int main(){
int n;cin>>n;
char w[n][15];
for(int i=0;i<n;i++){cin>>w[i];}
string_sort(w,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: 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 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[][11],int n){
int i,j;
	for(i=1;i<n;i++){
         j=i;
	while(j>0 && string_compare(a[j-1],a[j])==+1){
	for(int k=0;k<11;k++){
        swap (a[j-1][k],a[j][k]);
	j=j-1;
	}
      }
   }
}
int main(){
int n;
int count=0;
cin>>n;
char arr[n][11];
while(cin.getline(arr[count++],12));
string_sort(arr,n);
for(int i=0;i<n;i++){
	cout<<arr[i]<<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: 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;
int string_compare(char* a, char* b, int& A){
A++;
int i=0;
for(; ;i++){
if(a[i]==0 && b[i]==0) {return 0;}
else if(a[i]>b[i] || b[i]==0) {return -1;}
else if(a[i]<b[i] || a[i]==0) {return 1;}}}

void swaap(int& B,char* a, char* b){
int temp[12];B++;
int i=0,j=0,k=0;
for(;b[i]!=0;i++){temp[i]=b[i];}
temp[i]=0;
for(;a[j]!=0;j++){b[j]=a[j];}
b[j]=0;
for(;temp[k]!=0;k++){a[k]=temp[k];}
a[k]=0;}

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

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

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;

void swap(char *&a,char*&b){
 char t[100];
int i=0;
while(a[i]!='\0'){
 t[i]=a[i];
 i++;
}
t[i]='\0';

i=0;
while(b[i]!='\0'){
 a[i]=b[i];
 i++;
}
a[i]='\0';

i=0;
while(t[i]!=0){
 b[i]=t[i];
 i++;
}
b[i]='\0';
}

int strcom(char *a,char *b){

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

int strsort(char a[][100],int n,int &c){
c=0;bool flag;
int j;int count=0;
for(int i=1;i<n;i++){

j=i;
while(j>0){
 c++;

 if(strcom(a[j-1],a[j])==(-1)){
 swap(a[j],a[j-1]);
  count++;
 
}
 j=j-1;
  
 }

}
return count;
}

int main(){
 int n;
cin>>n;
int c;
char a[n][100];

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

int p=strsort(a,n,c);

for(int i=0;i<n;i++)
 cout<<a[i]<<endl;

cout<<c<<endl;
cout<<p;
}

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