CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

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

void swap (char a[20], char b[20]){
char temp[20] ;
temp[20]= a[20]; a[20] = b[20]; b[20] = temp[20]; return;
}

void input(char A[][20],int n){
for (int i=0;i<n;i++){
cin.getline(A[i],12);}}

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(char A[][20], int n,int &s)
{  s=0;
    int i, j;
    for (i = 0; i < n ; i++)
    { 
        // Last i elements will be in place after this for loop
        for (j = 0; j < n ; j++)
        
        {int l = 0;
        while(A[j][l]=A[j+1][l]){l++;}
        
            if (A[j][l] < A[j + 1][l])
                swap(A[j], A[j + 1]);
                s++;
        }
}}

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

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

char A[n][20];
input(A,n);
string_sort(A,n,s);
print(A,n);
cout<<s;}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

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(b[i]<a[i]){return -1;}
	i++;
}
return 0;
}
void swaps(char a[][12],int m,int n)
{	char t[12];int i;	
	for(i=0;a[m][i]!=0;i++)
	{t[i]=a[m][i];
	}
	t[i]=0;
	for(i=0;a[n][i]!=0;i++)
	{a[m][i]=a[n][i];
	}
	a[m][i]=0;
	for(i=0;t[i]!=0;i++)
	{a[n][i]=t[i];
	}
	a[n][i]=0;
}
void string_sort(char a[][12],int n,int &x,int &y)
{	
	for(int i=0;i<n-1;i++)
	{	for(int j=0;j<n-i-1;j++)
		{	x++;
			int k=string_compare(a[j],a[j+1]);
			if(k==1){swaps(a,j,j+1);y++;}
			
		}
	
	
	}



}



int main()
{	int n,x=0,y=0;
	cin>>n;int p=n+1;
	char a[14][12];
	for(int i=0;i<p;i++)
	{cin.getline(a[i],12);
	}
	string_sort(a,p,x,y);
	for(int i=0;i<p;i++)
	{cout<<a[i]<<endl;}
	cout<<x<<" "<<y;



}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

Student submission:
#include <iostream>
#include <cmath>

using namespace std;

#define ll long long
#define MAX 12

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

void swapStrings(char *a, char *b)
{
	char temp[MAX];
	for (int i = 0; i < MAX; i++) {
		temp[i] = a[i];
		a[i] = b[i];
		b[i] = temp[i];
	}
}

void string_sort(char string[][MAX], int n, int &ccompare, int &cswap)
{
	for (int i = 0; i < n - 1; i++) {
		bool flag = false;
		for (int j = 0; j < n - i - 1; j++) {
			ccompare++;
			if (string_compare(string[j], string[j + 1]) > 0) {
				swapStrings(string[j], string[j + 1]);
				cswap++;
				flag = true;
			}
		}
		if (!flag)
			break;
	}
}

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

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

	char string[15][MAX];

	for (int i = 0; i < n; i++)
		cin >> string[i];

	int ccompare = 0, cswap = 0;

	string_sort(string, n, ccompare, cswap);
	printStrings(string, n);
	cout << ccompare << " " << cswap << endl;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

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

void get2Darray (int A[][11], int n1, int n2){
int i,j;
for(i=0;i<n1;i++){
		for(j=0;j<n2;j++){
			cout << "row: " << i <<", column: " << j << endl;
			cin >> A[i][j];
		}
}
}
int string_length (const char* x) 
{
	int L = 0;
	while (x[L] != 0) L++;
return L;
}

void string_reverse(char* s, char* rev_s){
int n = string_length(s);
for(int i=0;i<n;i++) rev_s[n-1-i] = s[i]; 
rev_s[n] = 0;
}

int strcmp (const char* first, const 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;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

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

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


int stringlen(char* A){
	int l = 1;
	int i = 0;
	while(A[i] != '\0'){
		l++;
		i++;
	}
	return l;
}

void printarray(char* A){
	int n = stringlen(A);
	for(int i = 0; i<n; i++){
		cout << A[i];
	}
}

void stringswap(char A[][11], int a, int b){
	for(int i = 0; i<11; i++){
		char temp = A[a][i];
		A[a][i] = A[b][i];
		A[b][i] = temp;
	}
}


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 A[][11], int n, int* numcompare, int* numswap){

	*numcompare = 0;
	*numswap = 0;
	
		
	for(int i = 0; i<n-1; i++){
		bool flag = false; 
		for(int j = 0; j<n-i-1; j++){
			
			*numcompare = *numcompare + 1;;		
			if(string_compare(A[j],A[j+1]) == 1){
				
				stringswap(A,j,j+1);
				flag = true;
				*numswap = *numswap + 1;
			}
		}
		if(flag == false){
			break;
		}			
	}
		
}
int main(){
	int n;
	int numcompare;
	int numswap;
	
	cin >> n;
	char A[n][11];
	takeinput(A, n);
	
	string_sort(A, n, &numcompare, &numswap);
	for(int i = 0; i<n; i++){
		printarray(A[i]);
		
	}
	cout << endl;
	cout << numcompare << " " << numswap;
	
	
	
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: A
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

Student submission:
#include<iostream>
#define MAX 13
using namespace std;
void swap( char *first,char *second)
{
 int temp=*first;
*first=*second;
*second=temp;
}
int string_cmp(char first[][MAX],char second[][MAX], int x,int b)
{
int i=0;
           while (true){
                       if (first[x][i] == 0 && second[x+1][i] == 0) return 0;
                       if (first[x][i] == 0) return -1;
                       if (second[x+1][i] == 0) return +1;
                       if (first[x][i] < second[x+1][i]) return -1;
                       if (first[x][i] > second[x+1][i]) return +1;
                       i++;
                       b++;
                       }
                       return 0;
}
void bubble_sort(char string[][MAX], int n,int a,int b)
{
    for (int i = 0; i < n - 1; i++)
    {
        
        for (int j = 0; j < n - i - 1; j++)
        {
            if (string_cmp(string,string,j,b)=-1)
                {swap(&string[j], &string[j + 1]);
                a++;
        }
    }
}
}
int main(){
          int n,a=0,b=0;
          cin>>n;
          char string[n][MAX];
          for (int i=0;i<n;i++){
                               cin.getline(string[i],12);
                               }
         bubble_sort(string,n,a,b);
         for (int i=0;i<n;i++){
                              int x=0;
                              while(string[i][x]!=0)x++;
                              for(j=0;j<=x;j++){cout<<string[i][j];}
                              cout<<endl; 
                              }
          
          cout<<b<<" "<<a;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

Student submission:
#include<iostream>

using namespace std;

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



}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

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

char string_compare(char* a,char* b)
{
for(int i=0;i<n;i++)
{
if(a[i]<b[i])
{return 1;}
else if(a[i]>b[i])
{return 2;}
else {return 0;}
}
}

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

char**p=new char*[n];
for(int i=0;i<n;i++)
{
p[i]=new char[n];
}

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

for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<p[i][j];
} cout<<endl;
}
}



}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

Student submission:
#include<cstring>
#include<iostream>
using namespace std;
void int string_length (char *x){
int L = 0;
while (x[L] != ‘\0’) L++;
return L;
}
int main(){
char sq[1][11];
int count=0;
cout << "Enter at most 1 line with at most 11 characters :\n";
while (cin.getline(name[count++], 12)); 
for (int i=0; i<count; i++)
cout << "\t" << i << ". [" << sq[i] << "]" << endl;
}
int cin.getline(x,11);
char stringx[11]=" ";
char *x= stringx;
int string_length(stringx);
cout<<"L"<<" ";
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_reverse(char* s, char* rev_s){
int n = string_length(char *x);
for(int i=0;i<n;i++) rev_s[n-1-i] = s[i]; 
rev_s[n] = 0;
}
string_reverse();

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D
Problem: 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:

1. 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. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.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.

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

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

int string_compare (char *first, char *second,int &nc){
	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 copy (char *s, char *t){
while (*s++ = *t++);
}

void swap(char *a, char *b,int &ms){
	char temp[12];
	copy(temp,a);
	copy(a,b);
	copy(b,temp);
}


void bubble_sort(char A[][12], int n, int &ms, int &nc){
    int i, j;
    for (i = 0; i < n - 1; i++)
    {
        // Last i elements will be in place after this for loop
        for (j = 0; j < n - i - 1; j++)
        {
        	nc++;
            if (string_compare(A[j],A[j+1],nc)==-1){
                swap(A[j], A[j + 1]);
                ms++;
            }
        }
    }
}

int main(){
	int n;cin>>n;
	int numswap=0;
	int numcom=0;

	char a[n][12];

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

	bubble_sort(a,n,numswap,numcom);

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

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: 0
Rating C: 0
Rating D: Nothing Extra
Assigned grade: D