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 alphabetical order, -1 if the second string appears before the first in 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 selection-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_length (char *x)
{
	int L = 0;
	while (x[L] != 0) L++;
    return L;
}
void myswap(char *a,char *b){
    int m=string_length(a);
	int n=string_length(b);
	char t[m+n];
	for(int i=0;i<m+n;i++){
		t[i]=0;
	}
	for(int i=0;i<m;i++){
		t[i]=a[i];
		a[i]=0;
	}
	for(int i=0;i<n;i++){

		a[i]=0;
	}
	for(int i=0;i<n;i++){
		a[i]=b[i];
		b[i]=0;
	}
	for(int i=0;i<m;i++){
		b[i]=0;
    }
	for(int i=0;i<m;i++){
		b[i]=t[i];
	}
}
int string_compare(char *a,char *b){
	int m=string_length(a);
	int n=string_length(b);
	if(m==n){
	   int c=0;
	   for(int i=0;i<m;i++){
	      if(a[i]!=b[i]){
	         if(a[i]>b[i]) return -1;
	         else return +1;
	      }
	      else c=c+1;
	   }
	   if(c==m)return 0;
	}
	else{
	   int i=0,j=0,c=0;
	   while(i<m&&j<n){
	      if(a[i]>b[i])return -1;
	      else if(a[i]<b[i])return +1;
	      else c=c+1;
	      i=i+1;
	      j=j+1;
	   }
	   if(c==m)return +1;
	   else if(c==n)return -1;
	}
	return 0;
}
void string_sort(char a[][12],int m){
    int c=0,h=0;
	for(int i=0;i<m-1;i++){
	   int y=0;
       y=string_compare(a[i],a[i+1]);
       c=c+1;
       if(y==0)continue;
       else if(y==1){
          myswap(a[i],a[i+1]);
          h=h+1;
          i=0;
       }
       else if(y==-1)continue;
	}
	for(int i=0;i<m;i++){
	   cout<<a[i]<<endl;
	}
	cout<<c<<endl<<h;
}
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: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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<simplecpp>
using namespace std;

main_program{
	int n;
	cin>>n;
	for (int i=0;i=1;i++){
		for (int j=1;j<i;j++){
			cout<<"n is positive integer"<<
			cin>>n ;n<15
		}
		cout<<endl;
    }

	for (int m=15+n;m>80;m--){
		for (int p=n/2+1;p>1;p=p-1){
			cout<<"reverse alphabetical order"<<
		}
		cout<<endl;
	}
	cout<<endl;


 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: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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:
void GaussElim (float A[][MAX], float *b, int n){
        int i,j,k;
        float ratio;

        for(i=0;i<n-1;i++){
                if (A[i][i] == 0) {cout << "mathematical error"; return;}
                for(j=i+1;j<n;j++){
                        ratio = A[j][i]/A[i][i];
                        for(k=0;k<n;k++){
                                A[j][k] = A[j][k]-ratio*A[i][k];
                        }
                        b[j] = b[j]-ratio*b[i];
                }
        }
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 *x, char * y){
int i = 0;
while (true){
if (x[i] == 0 && x[i] == 0) return 0;
if (x[i] == 0) return -1;
if (y[i] == 0) return +1;
if (x[i] < y[i]) return -1;
if (x[i] > y[i]) return +1;
i++;
}
return 0;
}
int main()
{
int n;
cin>>n;
char arr[n];
cin.getline(arr,n);
int string_compare( arr[i], arr[i+1]);
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: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 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++;
}
}

void string_sort(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 main(){

unsigned int n;
cin>>n;

char chr[n];
char reverse[n];

for(int i=0;i<n;i++){
cin>>chr;
}

sting_sort(chr, reverse);

for(int i=0;i<n;i++){
cout<<reverse<<endl;
}
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: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 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;
}
int main(){
//int n;
//cin>>n;
char first[11];
char second[11];
cin.getline(first,11);
cin.getline(second,11);
cout<<string_compare(first,second);}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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;
#define max 12

void input_strings(char a[][max],int n)
{
	for(int i=0;i<n;i++)
	{	
		for(int j=0;j<11;j++){cin>>a[i][j];
		if(a[i][j]==0)i++;j=0;}
		a[i][11]=0;
	}
}

int string_compare(char p[],char q[])
{
	for(int i=0;i<12;i++)
	{
		if(p[i]>q[i]){return 1;break;}
		if(p[i]<q[i]){return -1;break;}
		else return 0;
	}
}	
			
void string_sort(char p[],char q[])
{
	char temp[12];
	for(int i=0;i<12;i++)
	{
		temp[i]=p[i];p[i]=q[i];q[i]=temp[i];
	}
}

void output_strings(char a[][max],int n)
{
 	for(int i=0;i<n;i++)
 	{
 		for(int j=0;j<12;j++)
 		{
 			if(a[i][j]==0){i++;j=0;}
 			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}

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

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 100

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++;
}
return 0;
}




int argmax (char **&a, int L, int &compare_count){
	int maxindex = 0;
	
	for(int j=1; j<L; j++){
		// update the index if a larger element is found
		compare_count++;
		if(string_compare(a[j],a[maxindex])==-1) maxindex = j;	
	}
	return maxindex;
}


void swap(char *&x, char *&y)
{
char* temp;
        temp=x;
	x=y;
	y=temp;
}



void stringSort(char **&a, int n, int &compare_count, int &swap_count)
	{
	compare_count=0;
	swap_count=0;
	
	
	
	
	for(int i=n; i>1;i--){
int maxindex = argmax(a,i,compare_count); 
swap(a[maxindex],a[i-1]);

	swap_count++;


}




}



int main(){

int n;
cin>>n;

char** a=new char*[max];

for(int i=0; i<n; i++)
	a[i]=new char[max];


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

int compare_count, swap_count;


stringSort(a, n, compare_count, swap_count);

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












/*
cin>>a[0];
cin>>a[1];

char* temp;

temp=a[0];
a[0]=a[1];
a[1]=temp;



cout<<a[0];
cout<<a[1];

*/

}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 *s1[], char *s2[]){
	for (int i=0; i<11; i++){
		if (s1[i]==s2[i]) return 0;
		else if (s1[i]<s2[i]) return 1;
		else return -1;
	}
}

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

}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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<simplecpp>

using namespace std;

void string_copy (char *dest, const char* source) {
	int i=0;
	while(source[i]!='\0'){
		dest[i]=source[i];
		i++;
	}
	dest[i]=source[i];
}

int ops=0, swaps=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;
}

int argmin(char ab[][20], int L){
	int minindex= 0; 
	for(int j = 1; j<L; j++){
		ops++;
		if(string_compare(ab[j],ab[minindex])==1)minindex=j;
	}
	return minindex;
}

void myswap(char *a, char *b){
	char temp[20];
	string_copy(temp,a);
	string_copy(a,b);
	string_copy(b,temp);
	
}

void string_sort(char data[][20], int n){
	for(int i=n; i>1;i--){
int minindex = argmin(data,i);
myswap(data[minindex],data[i-1]);
if(minindex!=(i-1))swaps++;
}
}



main_program{
	int n;
	cin>>n;
	char kohli100today[20][20];
	for(int i = 0 ; i<n; i++)cin>>kohli100today[i];
	string_sort(kohli100today,n);
	for(int i=0;i<n;i++)cout<<kohli100today[i]<<endl;
	cout<<ops<<endl;
	cout<<swaps<<endl;
}

Grading criterion: Eg Use of functions beyond what was instructed or any other nice quality
Rating A: Some extra nice qualities
Rating B: Nothing Extra
Rating C: 0
Rating D: 0
Assigned grade: B
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 alphabetical order, -1 if the second string appears before the first in 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 selection-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 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 arr[][100],int n){
	int cnt1=0;
	int cnt2=0;
	char*max=arr[0];
	int maxindex=0;
	for(int i=0;i<n-1;i++){
		char*temp=arr[i];
		for(int j=i+1;j<n;j++){
			if(string_compare(max,arr[j])==1){
				max=arr[j];
				maxindex=j;
				cnt1++;
			}
		}
		swap(arr[i],arr[maxindex]);
		if(arr[i]==temp){
			cnt2++;
		}
	}
	for(int i=0;i<n-1;i++){
		for(int j=0;j<n-i-1;j++){
			if(string_compare(arr[j],arr[j+1])==1){
				swap(arr[j],arr[j+1]);
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<arr[i]<<endl;
	}
	cout<<cnt2<<endl;
	cout<<cnt1;
}
int main(){
	int n;
	cin>>n;
	char arr[100][100];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	string_sort(arr,n);
}

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