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 fibo(int n){if(n==1){return 0;}
		else if(n==2){return 1;}
		else return fibo(n-1)+fibo(n-2);}
int main(){int n;
     cin>>n;
double a=0;
for(int i=1;i<n;i++){a=a+(1.0/fibo(i+1));}
cout<<fixed;
cout.precision(5);
double b,c=3.35989;
b=abs(a-c)/c;
cout<<a;
cout<<endl<<b;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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>
#include <cstring>

using namespace std;

int cswap=0,ccmp=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(char* a,char* b){
	cswap++;
	char temp[11];
	string_copy(temp,a);
	string_copy(a,b);
	string_copy(b,temp);
	
}

int string_compare (char *first, char * second){
	ccmp++;
	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 A[][11], int n) {
    int i, j;
    for (i=1;i < n;i++){ 
        j = i;
        while (j > 0) { 
        	int p=string_compare(A[j-1],A[j]);
		if(p==-1){
			swap (A[j],A[j-1]);	
        	}
        	j = j - 1;
        }
    }
}


int main(){

int n;
cin>>n;

char A[n][11];

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

cout<<"\n";

string_sort(A,n);

for (int i=0;i<n;i++){
	cout<<A[n-1-i]<<"\n";
}

cout<<ccmp;
cout<<"\n";
cout<<cswap;

}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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 100

int x=0,y=0;

void input_arr(int n, char A[][MAX]){
    for(int i = 0;i<n;i++) cin>>A[i];
}

void print_arr(int n, char A[][MAX]){
    for(int i = 0;i<n;i++) cout<<A[n-i-1]<<endl;
}

int len_string(char*A){
    int l = 0;
    while(A[l]!=0) l++;
    return l;
}

void myswap(char A[], char B[]){
    int m = len_string(A);
    int n = len_string(B);
    char temp[MAX];
    for(int i = 0;i<=m;i++){
        temp[i] = A[i];
    }
    for(int i = 0;i<=n;i++){
        A[i]=B[i];
    }
    for(int i = 0;i<=m;i++){
        B[i] = temp[i];
    }
    
}

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(int n, char A[][MAX]){
    int i, j;
    for(i = 1;i<n;i++){
        j=i;
        while(j>0){
            x++;
            if(string_compare(A[j-1],A[j])==-1){
                myswap(A[j-1],A[j]);
                y++;
                j--;
            }
            else break;
        }
    }
}

int main(){
    int n;
    cin>>n;
    char A[MAX][MAX];
    input_arr(n,A);
    string_sort(n,A);
    print_arr(n,A);
    cout<<x<<endl<<y;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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;

const int Max=15;

int m=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 myswap(char *a,char *b){
char t[Max];
string_copy(t,a);
string_copy(a,b);
string_copy(b,t);
}

*/
int string_compare(char *a, char *b){
m++;
int i = 0;
while (true){
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return +1;
i++;
}
return 0;
}

void string_sort(char inp[][Max],int n){
int i,j,s;
s=0;
for (i=1;i < n;i++){
j = i;
while ((j > 0) && ((string_compare(inp[j-1],inp[j]))==1)) {
swap(inp[j-1],inp[j]);
j=j-1;
s++;
}
}
for(int k=n-1;k>=0;k--){
cout<<inp[k]<<endl;
}
cout<<m<<endl;
cout<<s;
}


int main(){
int n;
cin>>n;
char inp[Max][Max];
//while (cin.getline(name[count++], 20));
for(int i=0;i<n;i++){
cin>>inp[i];
}
string_sort(inp,n);
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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<bits/stdc++.h>
#define MAX1 15
#define MAX2 12

using namespace std;

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

int* string_sort(char arr_s[][MAX2], int n)
{
	int* ans = new int[2];
	ans[0]=0;
	ans[1]=0;
	for(int i=1; i<n; i++)
	{
		int j=i;
		while(j>0)
		{
			ans[0]++;
			if(string_compare(arr_s[j-1] , arr_s[j]) == 1)
			{
				swap(arr_s[j-1],arr_s[j]);
				ans[1]++;
				j--;
			}
			else
				break;
		}
	}
	return ans;
}

int main()
{
	int n;
	cin >> n;
	char arr_s[MAX1][MAX2];
	for(int i=0; i<n; i++)
		cin >> arr_s[i];
	
	int* ans = string_sort(arr_s, n);
	for(int i=n-1; i>=0; i--)
		cout << arr_s[i]<<endl;
	
	cout << ans[0]<<endl;
	cout << ans[1]<<endl;
	delete ans;
	
	return 0;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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 <simplecpp>
#define maxsize 12

int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
else if (first[i] == 0) return +1;
else if (second[i] == 0) return -1;
else if (first[i] < second[i]) return +1;
else 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(char* e, char* f)
	{
	char temp;
	string_copy(&temp,&e);
	string_copy(&e,&f);
	string_copy(&f,&temp);
	}

main_program{
int n;
cin>>n;
char a[n][maxsize];
for (int i=0;i<n;i++)
	{
	cin>>a[i];
	}
cout<<endl;
for (int i=0;i<n;i++)
	{
	cout<<a[i]<<" ";
	}
swap(&a[0],&a[1]);
cout<<a[0]<<a[1];
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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>
#include <cstring>
using namespace std;
#define MAX 12
void copy(char *a,char *b)
{
int i;
for(i=0;i<strlen(b);i++)
{
a[i]=b[i];
}
a[i]=0;
}
int string_compare(char *a,char *b,int &comp)
{
  comp++;
  for(int i=0;i<MAX;i++)
  {
    if(a[i]<b[i]) return 1;
    if(b[i]<a[i]) return -1;
    if(a[i]==0 && b[i]!=0) return 1;
    if(b[i]==0 && a[i]==0) return -1;
  }
return 0;
}
void string_sort(char a[][MAX],int n,int &comp,int &swap)
{
comp=0;
swap=0;
for(int i=0;i<n-1;i++)
{
  int j=i+1;
  while(string_compare(a[j],a[j-1],comp)==1&&j!=0)
  { 
      char temp[MAX]="";
      copy(temp,a[j]);
      copy(a[j],a[j-1]);
      copy(a[j-1],temp);
      j--;
      swap++;
  }
}
}
int main()
{
  int n;
  cin>>n;
  char a[n][MAX];
  for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
  int comp;
  int swap;
  string_sort(a,n,comp,swap);
  for(int i=n-1;i>=0;i--)
  {
    cout<<a[i]<<endl;
  }
  cout<<comp<<endl;
  cout<<swap<<endl;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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 15
int ccomp = 0; int cswap = 0;

int string_compare(char* first, char* second){
int i=0;
while(true){
	if(first[i]==second[i]) 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){
int i=0;
for(i=0; i<12; i++){
	char temp = A[i];
	A[i] = B[i];
	B[i] = temp;
	}
cswap++;
}

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

void cin_strings(char A[MAX][MAX], int n){
	int i=0;
	for(i=0; i<n; i++) cin>>A[i];
	}

void cout_strings(char A[MAX][MAX], int n){
	int i=0;
	for(i=0; i<n; i++) {
		cout<<A[i]<<endl;
		}
	}

int main(){
int n; cin>>n;
char A[MAX][MAX];
cin_strings(A,n);
string_sort(A,n);
cout_strings(A,n);
cout<<ccomp<<" "<<cswap<<endl;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
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;

void charswap(char* &a,char* &b){
	char* c=&a[0];
	a=&b[0];
	b=&c[0];
}
char** dynchar2D(int m,int n){
	char** A= new char*[m];
	for(int j=0;j<m;j++){
		A[j]= new char[n];
	}
	return A;
}

void charout(char** A,int N){
	for(int j=0;j<N;j++){
		cout<<A[j]<<endl;
	}
}

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_sort(char** A,int N,int &comp,int &sww){
	int i=1;
	for(i=1;i<N;i++){
		for(int j=i;j>0;j--){
			if(string_compare(A[i],A[i-1])==1){comp++;break;}
			
				sww++;
				charswap(A[i],A[i-1]);
			
		}
	}
}

int main(){
	int N;cin>>N;int comp=0;int sww=0;
	char** A=dynchar2D(N,20);
	for(int i=0;i<N;i++){
		cin.getline(A[i],20);
	}
	cout<<endl;
	string_sort(A,N,comp,sww);
	charout(A,N);
	cout<<comp<<endl;
	cout<<sww;
}

Grading criterion: Quality and number of comments
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C