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>
#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: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;
int 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: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;

int 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: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;
int 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: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;

void 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: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;
#define Max 20
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 swap(char*&A,char*&B){
	char*temp;
	temp=A;
	A=B;
	B=temp;}
void string_sort(char A[][Max],int n){
       int c=0,l, s=0,i,j;
	for(i=0;i<n;i++){
		for(j=(i-1);j>=0;j--){l=string_compare(A[i],A[j]);c++;
				if(l==-1){swap(A[i],A[j]);s++;}
				if(l==1){break;}
				else if(l==0){break;}
				  }}
	for(i=(n-1);i>=0;i++){cout<<A[i]<<"\n";}
	cout<<"number of string_compare operatons ="<<c;
	cout<<"number of string swaps ="<< s;}
int main(){
int n,i;
cin>>n;
char A[n][Max];
for(i=0;i<n;i++){cin>>A[i];}
string_sort(A,n);
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include<iostream>
using namespace std;

#define MAX 200

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


void token(char fir[],char ans[][MAX]){
   int i=0,j=0,k=0;
   while(k<len(fir)){
   if(fir[k]==' '){ j=0;i++; }
   else{
     ans[i][j]=fir[k];j++;
   }
   k++;
   }
}

int string_compare(char fir[],char sec[]){
  int i=0;
  while(true){
  if(fir[i]==0 && sec[i]==0){
  return 0;
  }
  else if(fir[i]==0){return 1;}
  else if(sec[i]==0){return -1;}
  else if(fir[i]<sec[i]){
  return 1;
  }
  else if(sec[i]<fir[i]){
  return -1;
  }
  i++;
  }
}

void swap(char A[],char B[]){
   for(int i=0;i<max(len(A),len(B));i++){
   char temp=A[i];
   A[i]=B[i];
   B[i]=temp;
   }
}

void string_sort(char A[][MAX],int n){
  int ans=0,sw=0;
  for(int i=0;i<n;i++){
    ans++;
    int j=i-1;
    bool flag=false;
    while(j>0 && string_compare(A[j],A[i])==-1){
    swap(A[j],A[j-1]);
    bool flag=true;
    j--;
    }
    if(flag){
    sw++;}
    }
    /*for(int j=0;j<i;j++){
    int com=compare(A[i],A[j]);
    ans++;
    if(com==-1){
    
    break;}
    }*/
    for(int i=0;i<n;i++){
cout<<A[i]<<endl;
}
cout<<ans<<endl<<sw<<endl;
}

int main(){


int n;
cin>>n;
char inp[MAX];
//cin.getline(inp,MAX);
char arr[MAX][MAX];
for(int i=0;i<n;i++)
{cin>>arr[i];}
string_sort(arr,n);



return 0;
}

Grading criterion: Is string_compare implemented properly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Code not there or totally wrong
Assigned grade: A
Problem: Title - Sorting strings using insertion sort

Problem Description: 
Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. A function string_sort which sorts the character strings using the insertion-sort algorithm taught in class. Your program should then print out the strings sorted in reverse alphabetical order, starting from the last to the first. Your program should also print the number of string_compare operations (i.e. how many times the string_compare routine was called) and the number of string swaps performed. 

Input Format - integer n, and a set of n character strings
Output Format - Print out the strings in the suggested order, one string on a new line

Constraints
n is a positive integer, n < 15
The maximum length of any of the strings should be 11, excluding the NULL character.
The character strings should contain only lower case alphabets

Sample input and output
Input: 4 efs abc zbdf word
Output (on console): zbdf word efs abc 4 2

Student submission:
#include <iostream>
using namespace std;
#define MAX 100
void swap_string (char*a,char*b,int &l){
l++;
char p[MAX];
int i=0;
for (i=0;a[i]!=0;i++){
p[i]=a[i];
}p[i]=a[i];
int j=0;
for (j=0;b[j]!=0;j++){
a[j]=b[j];
} a[j]=b[j];
int k=0;
for (k=0;p[k]!=0;k++){
b[k]=p[k];
} b[k]=p[k];
}
int string_compare (char*a,char*b,int &k){
k++;
int i=0,j=0;
while(a[i]!=0&&b[j]!=0){
if (a[i]<b[j])return -1;
else if (a[i]>b[j])return 1;
else {i++;j++;}
}
return 0;
}
void string_sort (char A[][MAX],int n,int &k,int&l ){
for (int i=1;i<n;i++){
for (int j=i;j>0&&A[j-1][0]<A[j][0];j--){
int m=string_compare(A[j],A[j-1],k);
if (m==1) swap_string(A[j],A[j-1],l);
}
}
}
int main(){
int n;
cin>>n;int k=0;int l=0;
char A[n][MAX];
for (int i=0;i<n;i++){cin>>A[i];}
string_sort(A,n,k,l);
for (int i=0;i<n;i++){cout<<A[i]<<endl;}
cout<<k<<endl;
cout<<l;
}

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