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* 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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
Assigned grade: B
Problem: Title - Sorting strings using insertion sort

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

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

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

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

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

void 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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
Assigned grade: C
Problem: Title - Sorting strings using insertion sort

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

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

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

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

Student submission:
#include<iostream>
using namespace std;
#define 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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
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 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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
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 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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
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>
#define MAX 11
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]<second[i])return +1;
if(first[i]>second[i])return -1;
i++;
}
return 0;
}
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 swap_f(char *first,char *second){
char temp[MAX];
string_copy(temp,first);
string_copy(first,second);
string_copy(second,temp);
}
void string_sort(char A[][MAX],int n,int &k,int &r){
int i,j;
int s=0;
for(i=1;i<n;i++){
j=i;r++;
while(j>0 && string_compare(A[j-1],A[j])==1){
swap_f(A[j-1],A[j]);
j=j-1;k++;s++;
}

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

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
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;
const int N=11;

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 str_swap(char* a, char *b){
    char * temp;
    while(*temp++=*a++);
    while(*a++=*b++);
    while(*b++=*temp++);
}
void string_sort(char a[][N],int n,int &k,int &l){

    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        
        while (j>0 && string_compare(a[j],a[j-1])==-1) { 
            swap (a[j],a[j-1]);
            j = j - 1;
            k=k+1;
            l=l+1;
            if (string_compare(a[j],a[j-1])!=-1) k=k+1;
        }}
        
    }




int main(){
    int n,k,l;
    k=l=0;
    cin>>n;
    char a[n][N];
    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: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
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 I=0;
int length(char *c)
{
	int i=0;
	while(c[i]!=0)
	i++;

	return i;
}

int string_compare(char *a,char *b)
{
	I++;
	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++;
	}
	return 0;
}
void string_sort(char c[][12],int n,int &s)
{
	int i,j,k;
	for(int i=1;i<n;i++)
	{
		j=i;
		while(j>0 && string_compare(c[j-1],c[j])==-1)
		{
		char temp[12];
		for(k=0;k<=length(c[j]);k++)
		temp[k]=c[j][k];

		for(k=0;k<=length(c[j-1]);k++)
		c[j][k]=c[j-1][k];

		for(k=0;k<=length(temp);k++)
		c[j-1][k]=temp[k];

		s++;

		j--;
		}
	}
}

int main()
{
	int n,s=0;
	cin>>n;

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

	string_sort(c,n,s);

	for(int i=n-1;i>=0;i--)
	cout<<c[i]<<endl;

	cout<<I<<endl<<s;
	return 0;
}

Grading criterion: Quality of variable names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor Naming of variables
Rating D: 0
Assigned grade: A