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;
void copy(char *s, char *t)
{
	while (*s++ = *t++); 
}
void swap(char *s,char *t)
{
	char *temp;
	copy(temp,s);
	copy(s,t);
	copy(t,temp);
}
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++;
	}
}
int s1(char str[][], int l)
{
	int m=0;
	for(int j=1;j<l;j++)
	{
		if(string_compare(str[m],str[j]== 1){m=j;break;}
	}
	return m;
}
void sort(char str[][],int n)
{
	for(int i=n; i>1;i--)	
	{
		int m=s1(str,i);
		swap(&str[m],&str[i-1]);
	}
}
int main()
{
	int n;
	cin>>n;
	char string_2d[11][n];
	for(int i=0;i<n;i++)
	{
		cin>>string_2d[i];
	}
	sort(string_2d,n);
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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++;
}}
void swap (char *a, char *b)
{
    float temp;
    temp = *a;
    *a = *b;
    *b = temp;
    
}

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


void selection_sort (char *data, int n,int* acomp,int* aswp)
{
    for(int i=n; i>1;i--)
    {  
        int maxindex = argmax(data,i);
        *acomp=(i-1)+*acomp;
        // get the maximum of the first i elements
        if(aswp>=0)
        {swap(&data[maxindex],&data[i-1]); *aswp= *aswp+1;}
        
         // refer to earlier slides for this!
        // at this point, data[i-1] will be in the correct position for a sorted array
    }
}

int main()
{
  int n,comp=0,swp=0;
 
  
  cin>>n;
  char arr[n][11];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  selection_sort(arr[11],n,&comp,&swp);
  
  for(int i =n-1;; )
  {if(i<0)break;
    cout<<arr[i]<<endl;
    i--;
    
  }
  cout<<comp<<endl;
  cout<<swp<<endl;
  
  
  

}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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 12
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 string_sort(char a[MAX][MAX],char b[MAX][MAX], int m, int& n, int& l){
     l=0;
     n=0;
     for(int i=0; i<m; i++){
          int t=0;
          for(int j=i; j<m-1; j++){
               if(string_compare(a[j], a[j+1])==-1){
                    t=j+1;
                    n++;
               }
          }   
          int k=0;  
               while(a[t][k]!=0){
                    b[i][k]=a[t][k];
                    k++;}
                    b[i][k]=0;
               if(i!=t){
                    l++;     
          }          
          
     }
}
int main(){
     int m;
     cin >> m;
     char a[MAX][MAX];
     char b[MAX][MAX];
     for(int i=0; i<=m; i++){
          cin.getline(a[i],12);
     }
     int l;
     int n;
     string_sort(a, b, m, n, l);     
     for(int i=0; i<=m; i++){
          cout << b[i] << endl;
     } 
     cout << n << endl << l;
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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;
}

int minindex(char *a,int l)
{
int mini=0;
for (int j=1;j++;j<l)
{
    if (string_compare(a[j],a[mini])==1) mini=j;
}
return mini;
}


int string_sort(char *a, int n)
{
int c2=0;
for (int i=n;i>1;i--)
{    
    int mini=minindex(a,n);
    int temp=a[i-1];
    a[i-1]=a[mini];
    a[mini]=temp;
    c2+=1;
}
return c2;
}
    


int main()
{
int n;
cin>>n;
char arr[n][11];
for (int i=0;i<n;i++)
{    
    cin>>arr[i];
}
k2=string_sort(arr,n);
for (int i=0;i<n;i++)
{
    cout<<arr[i]<<endl;
}
cout<<k2;
cout<<k2;


}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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(char * &a, char * &b)
{ int temp=a;
a=b;
b=temp;
} 

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

void stringsort(char b[][13],int n)
{
int k=string_compare;
for(int j=0; j<13; j++)
{
for(int i=0; i<n; i++)
{
 if(k=-1) swap(b[][i],b[][i+1]);

}
}}
int main()
{
int n;
cin>>n;
char a[n+1][13];
int count=0;
while(cin.getline(a[count++],13));
stringsort(a,n);
for(int j=0; j<13; j++)
{
for(int i=0; i<n; i++)
{
cout<<a[i][j];
}}
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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(){
	char x[100]; 
	cin.getline(x,n);

}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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>

void swap (float *a, float *b)
{
    float temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

int argmax (float *marks, int L)
{
	int maxindex = 0;
	for(int j=1; j<L; j++){
			if(marks[maxindex] < marks[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[maxindex],&data[i-1]); 
           }
}


main_program
{
    float A[100];
    int i,n;
    cin >> n;

    for (i= 0; i < n; i++)
    {
        
        cin >> A[i];
    }
    for (i= 0; i < n-1; i++)
    {
        cout << "uppercase"<<endl;
    }


    selection_sort(A,n);
    
    for (i= 0; i < n-1; i++)
    {
        cout << "lowercase"<<endl;
		cout<<1<< endl<<1;
}
    }

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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 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<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_swap(char *A1,char* A2)
{
int len1=strlen(A1);
int len2=strlen(A2);
int i,j;
i=j=0;
while(i<len1 && j<len2)
{
char temp=A1[i];
A1[i]=A2[j];
A2[j]=temp;
i++;
j++;

}

while(i<len1)
{
A2[j]=A1[i];
i++;
j++;
}
while(j<len2)
{
A1[i]=A2[j];
i++;
j++;
}
}


void string_sort(char sent[][12], int n)
{
for(int i=n; i>1; i--)
{
int maxindex=0;
for(int j=1; j<i; j++)
{

int c=string_compare(sent[j], sent[maxindex]);
if(c==1){maxindex=j;}
}
string_swap(sent[maxindex], sent[i-1]);
}

}


int main()
{
	int n;
	cin>>n;
	char sent[n][12];
	 int sentc[n];
 int sents[n];
int count=0;
	while (cin.getline(sent[count++], 12)); //terminated by ctrl d
	string_sort(sent, n);
for(int j=0; j<n; j++)
	{
cout<<sent[j]<<endl;
	 //0entc[j]=0;
 	//sents[j]=0;
	}

}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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 11
using namespace std;
void input_matrix(char A[MAX][2], int n){
cin.getline(A,n);
for(int i=0; i<n; i++){
	for(int j=0; j<2; j++){
	cout << "Enter the string at row" << i << ", column " << j << endl;
		cin >> A[i][j];
		}
	}
}
void matrix(char A[MAX][2], int n){
	for (int i=0; i<n; i++){
		for(int j=0; j<2; j++){
		cout << A[i][j] << " ";
		}
	cout << endl;
		}
	cout << endl;
}
int main(){
char A[MAX][2];
int n;

input_matrix(A,n);
matrix(A,n);
}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
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 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;

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 n){
	int maxindex = 0;
	for(int j=1; j<n; j++){
		
		if(string_compare(A[maxindex],A[j])==1	
	}
	return maxindex;
}

void selection_sort(char **A,int n)
{
for(int i=n;i>1;i--)
{
int maxind=argmax(A[],i);
char temp=A[maxindex];
A[maxindex]=A[i-1];
A[i-1]=temp;
}

}

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

selection_sort(A,n);

for(int i=0;i<n;i++)
{
while(A[i]!='\0') {cout<<A[i];}
}



}

Grading criterion: string_compare implementation
Rating A: Fully Correct
Rating B: Almost Correct
Rating C: Tried something in somewhat right direction
Rating D: Code not there or totally wrong
Assigned grade: B