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_compare(char*A,char*B){
   int i=0;
   while(true){
   if(A[i]==0&&B[i]==0) return 0;
   if(A[i]==0) return 1;
   if(B[i]==0)return -1;
   if(A[i]<B[i]) return 1;
   if(A[i]>B[i]) return -1;
   i++;
   }
   return 0;
   }
void swap(char& a,char&b){
    char temp=a; a=b;b=temp;
   }
char minimum(char names[][13],int m){
 	char min[13];
 	min[]=names[0];
 	for(int i=0;i<m;i++) if( string_compare(min,names[i])==-1) min[]=names[i];
 	return min;
 }
 
void string_sort(char names[][13],n){
	for (int i=n;i>=0;i--){
	char min[]=minimum(names,i);
	swap(min,names[i][]);
}
}
int main(){
	int n; cin>>n;
	char names[16][13];
	for(int i=0;i<n;i++)  cin>>names[i];
	string_sort(names,n);
	for(int i=0;i<n;i++) cout<<names[i]<<endl;



return 0;
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
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 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 15

using namespace std;

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];
}

int string_compare(char A[], char B[])
{
	int i=0;
	while(A[i] != '\0' && B[i] != '\0')
	{
		if(A[i] < B[i])
		{
			return 1;
		}
		else if(A[i] > B[i])
		{
			return -1;
		}
		i++;
	}
	if(A[i] < B[i])
	{
		return 1;
	}
	else if(A[i] > B[i])
	{
		return -1;
	}
	return 0;
}

void string_sort(char A[][MAX], int n)
{
	char max[MAX];
	int numcomp = 0;
	int numswap = 0;
	for(int i=0; i<n-1; i++)
	{
		string_copy(max, A[i]);
		int maxindex = i;
		for(int j=i+1; j<n; j++)
		{
			int k = string_compare(max, A[j]);
			numcomp++;
			if(k == 1) 
			{
				string_copy(max, A[j]);
				maxindex = j;
			}	
		}
			
		if(maxindex != i)
		{
			numswap++;
			swap(A[maxindex], A[i]);
		}
	}
	for(int i=0; i<n; i++) cout << A[i] << endl;
	cout << numcomp << endl;
	cout << numswap;
}

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

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
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 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 read(char str[][MAX],int n){

for(int i=0;i<n;i++){int j=0;
	while(a[i][j]!='\n'){cin>>str[i][j];j++;}
}
}

int string_compare(char str[][MAX]){
     int b[2];
    char str[2][MAX];
    for(int i=0;i<2;i++){int j=0;
	   while(str[i][j]!='\n'){cin>>str[i][j];j++;}
	   b[i]=j;
    } 
int p=0,q=0;
   while(p<=b[0] && q<=b[1]){if(str[0][p]<str[1][q]){return 1;}
	        else if(str[0][p]>str[0][q]){return -1;}
		else{p++;q++;}
   }
   if(p==q){return 0;}
}


void string_sort(char str[][MAX],int n)

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
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>
int string_length (char *x)
{
	int L = 0;
	while (x[L] != '\0') L++;
return 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++;
cout<<i;
}
return 0;
}
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; 
cout<<rev_s[n];}
main_program{
char first[11],second[11],rev_first[11],rev_second[11];
int i, n;
cin>>n;
for(i=0;i<n;i++)cin>>first[i];
for(i=0;i<n;i++)cin>>second[i];
string_compare(first,second);
string_reverse(first,rev_first);
string_reverse(second,rev_second);
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
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>
#include<string.h>
#include<stdio.h>
#define MAX 100
using namespace std;
int string_compare(char str1[MAX],char str2[MAX]){
cin>>str1;
cin>>str2;
if(cmpr(str1,str2)>0) return 1;
if(cmpr(str2,str1)<0) return -1;
if(cmpr(str1,str2)==0) return 0;
}
void string_sort(char str1){
for(int i=0;i<strlen(str1);i++){
  str2[i]=str1[strlen(str)-1-i];
  }
}
int main(){
int n;
cin>>n;
char str1[MAX];
char str2[MAX];
cin.getline(str1,n);
cin.getline(str2,n);
string_compare(str1,str2);
string_sort(str1);
for(int i=0;i<strlen(str2);i++){
  cout<<str2[i];
  }
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
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 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 *a, char *b)
{
int i=0;
while(true){
if(a[i]==0 && b[i]==0)
return 0;
if(a[i]==0)
return -1;
if(b[i]==0)
return +1;
if(a[i]<b[i])
return -1;
if(a[i]>b[i])
return +1;
i++;
}
return 0;
}*/

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
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 main() {
    int i,j;
    void print_array_values (int *a, int n){
	for (int i = 0; i < n; i++) cout << a[i];
}
void input_array_values (int *a, int n){
	for (int i = 0; i < n; i++) cin >> a[i];
}
void print_array_values (int a [], int n){
	for (int i = 0; i < n; i++) cout << a[i];
}
void input_array_values (int a [], int n){
	for (int i = 0; i < n; i++) cin >> a[i];
}
void double_array_values (int a [], int n){
	for (int i = 0; i < n; i++) a[i] *= 2;
}
int i; 
for(i=0;i<numbins;i++) hist[i] = 0; 
for(j=0;j<numbins;j++){
if (scores[i] <= bin_end_values[j]) { hist[j]++; break;} 

}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
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>
int main( ){
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;
}}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
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>
#include <cmath>
#include <cstring>
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 A[][500], int n)
{
    int nswap=0;
    int ncomp=0;
    for (int i=n-1; i>=0; i--)
    {
        int minI = i;
        for (int j=0; j<i+1; j++)
        {
           ncomp++; 
           if (string_compare(A[j], A[minI])==1)
           {
                swap(A[minI], A[j]);
                nswap++;
           } 
        }    
    }
    for(int i=0; i<n; i++)
    {
        cout<<A[i]<<endl;
    }
    cout<<ncomp-2<<endl<<nswap;;
}

int main()
{
    int n;
    cin>>n;
    char A[500][500];
    for (int i=0; i<n; i++)
    {
        cin>>A[i];
    }
    string_sort(A, n);
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
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 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 argmin (char data[][12], int L){
int minindex = 0;
for(int j=1; j<L; j++){
if (string_compare(&data[minindex][12],&data[j][12])==-1){
 minindex = j;	
}
}return minindex;}


void string_sort (char data[][12], int n){
for(int i=n; i>1;i--){
int minindex = argmin(data,i);
char temp=data[minindex];
data[minindex]=data[i-1];
data[i-1]=temp;
}
}


int main(){
int n;
cin>>n;
char a[n][12];
char el[12];



//input
for (int i=0;i<n;i++){
cin>>el;
int j=0;
while(el[j]!='\0'){
j+=1;
}
for (int k=0;k<=j;k++){
a[i][k]=el[k];
}}

string_sort(a,n);

//output
for (int i=0;i<n;i++){
cout<<a[i];
}
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
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 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;
void swap (float *a, float *b)
{
float temp;
temp =*a;
*a = *b;
*b = temp;
}
int argmax(float *length, int L)
{
int maxindex=0;
for(int j=1; j<L; j++)
{
if(length[maxindex] <length[j])
maxindex=j;
}
return maxindex;
}
void selection_sort (float *data, int n)
{
for(int i=n;i>1;i--)
{int maxindex= argmax(data,i);

swap(&data[maxidex],&data[i-1]);
}
}
int main(){
}

Grading criterion: Sort is implemented in function string_sort.
Rating A: If implemented in function
Rating B: If not implemented in function.
Rating C: 0
Rating D: 0
Assigned grade: B