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 p=0;
int q=0;

int string_compare (char *first, char * second)
{
	p=p+1;
	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 swap (char* &x, char* &y)
{
	char *temp=x;
	x=y;
	y=temp;
}


void string_sort (char s[][15], int n)
{
	for (int j=0; j<n-1; j++)
	{
	int mini = 0;
		for (int i=0; i<n-1-j; i++)
		{
			if (string_compare (s[i+1],s[mini]) == 1) {mini = i+1;}
		}
		if (mini!=n-j-1) {swap (s[mini],s[n-j-1]); q++;}
		
	}
	
}

int main ()
{
	int n;
	
	cin >> n;
	char s[n][15];
	for (int i=0; i<n; i++)
	{
		cin >> s[i];
	}
	
	string_sort(s,n);	
	
	for (int i=0; i<n; i++)
	{
		cout << s[i]<<endl;
	}
	cout << p << "\n" << q;
	
}

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<cstring>
#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 name[n][12];
	int count=0;
	for(;count<=n;count++){
		cin.getline(name[count],12);
	}
	for(count = 0;count<=n;count++){
		cout << name[count] << " " ;
	}
	int swaps = 0;
	cout << swaps;
	
}

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>
#include<cstring>
using namespace std;



int string_compare(char* a,char* b){

	if (a==b){
		return 0;
	}
	for (int i=0;i<min(strlen(a),strlen(b));i++){
		if (a[i]>b[i]){
			return 1;

		}
		if (b[i]>a[i]){
			return -1;

		}
	}
	if(strlen(b)>strlen(a)){

		return -1;

	}
	if(strlen(a)>strlen(b)){

		return 1;

	


}
}



char* string_sort(char** a ,int n){

	for(int i=n;i>0;i--)
	for(int =0;j<n;j++){

	}






}






int main(){

	int m,n;
	cin>>n;
	char** x=new char*[n];
	for(int i=0;i<n;i++){
		x[i] =  new char [13]; 
	}
	for(int j=0;j<n;j++){
		char s[12];
		cin>>s;

	 for(int i=0;i<strlen(s)+1;i++){
		

		x[j][i]=s[i];
}
}

char a[13];
char b[13];
string_compare(a,b);
	
// 	for(int i=0;i<n;i++){
// 		cout<<x[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;
#define max 12
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 copy_char(char *a,char* b)
{
	int i=0;
	while(a[i]!=0)
	{
		b[i]=a[i];i++;
	}
	b[i]=0;
}
int min_arg(char a[][max],int n,int& nc)
{
	int m=0;
	for(int i=1;i<n;i++)
	{
		if(string_compare(a[i],a[m])==1)
		{
			m=i;
		}
		nc++;
	}
	return m;
}
void string_sort(char a[][max],int n,int& ns,int& nc)
{
	for(int i=n;i>1;i--)
	{
		int minind=min_arg(a,i,nc);
		char temp[max];
		copy_char(a[i-1],temp);
		copy_char(a[minind],a[i-1]);
		copy_char(temp,a[minind]);
		if(minind!=n-i-1)ns++;
	}
}
int main()
{
	int n,nc=0,ns=0;
	cin>>n;
	char a[n][max];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	string_sort(a,n,ns,nc);
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<endl;
	}
	cout<<nc<<endl;
	cout<<ns;
}

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>
#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 swap ( char *a,char *b)
{
float temp;
temp=*a;
*a=*b;
*b=temp;
}
int string_length (char *x)
{
	int L = 0;
	while (x[L] != '\0') L++;
return L;
}
int minindex( char *x,int l)
{
	int minindex=0;
	for(int j=1;j<l;j++){
		if(x[minindex] > x[j]) minindex=j;
		}
		return minindex;
}
void string_sort( char *w )
{
       int n;
	n = string_length(w);
	for(int i=n;i>1;i--)
	{
	int min = minindex(w,i);
	swap(&w[min],&w[i-1]);
	}
}
int main()
{

char w[20];
cin>>w;
string_sort(w);
cout<<w;
}

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>
#include<cstring>
using namespace std;
int string_compare(char arr[][12], int n ){


}
int string_sort(char arr[][12], int n){

}



int main(){
int n;
cin>>n;
char arr[15][12];
for(int i=0; i<n; i++){
    for(int j=0; arr[i][j]!='\0'; j++){
    cin>>arr[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<iostream>
using namespace std;
#define MAX 100
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 input_char(char A[][MAX], int n){
	
	for(int i=0;i<n;i++){
		for(int j=0;j<9;j++){
			cin >> A[i][j];
			
		}
	}
}
void output_char(char A[][MAX], int n){
	int s=1;
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<9;j++){
			cout<<A[i][j];
		}
		cout<<endl;
	}
	cout<<s<<endl<<s;
}
int main(){
	int n;
	cin>>n;
	char A[n][MAX];
	input_char(A,n);
	output_char(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 <iostream>
using namespace std;
#define maxsize 11

void swap(char *a[maxsize], char *b[maxsize], int *counter){
	char temp;
	temp = a;
	a = b;
	b = temp;
	counter++;
}

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

int main(){
	int n;
	cin >> n;
	char array_string[n];
	for(int i=0; i<n; i++){
		cin >> array_string[i];
	}
	
	int comparecounter=0;
	int swapcounter=0;
	
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(string_compare(array_string[i], array_string[j], &comparecounter)==-1){
				swap(array_string[i], array_string[j], &swapcounter);
				break;
			}
			else if(string_compare(array_string[i], array_string[j], &comparecounter)==0){
				continue;
			}
			else if(string_compare(array_string[i], array_string[j], &comparecounter)==1){
				continue;
			}
		}
	}
	
	for(int i=0; i<n; i++){
		cout << array_string[i];
	}
	cout << comparecounter;
	cout << swapcounter;
}

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 20
using namespace std;

void string_swap(char *a,char *b){

	int la=0,lb=0;
	for(int i=0;a[i]!=0;i++){
	
		la++;
	}
	for(int j=0;b[j]!=0;j++){
	
		lb++;
	}
	int c[la];
	for(int i=0;i<la;i++){
	
		c[i]=a[i];
	}
	c[la]='\0';
	
	for(int i=0;i<lb;i++){
	
		a[i]=b[i];
	}
	a[lb]='\0';
	
	for(int i=0;i<la;i++){
	
		b[i]=c[i];
	}b[la]='\0';
}
	
int string_compare(char *a,char *b){

	int la=0,lb=0;
	for(int i=0;a[i]!='\0';i++){
		la++;
	}
	for(int i=0;b[i]!='\0';i++){
		lb++;
	}
	
	int k=0;
	for(int i=0;(a[i]==b[i]) && a[i]!=0 && b[i]!=0;i++){
	
		k++;
	}
	if(k==la && k==lb){
	
		return 0;
	}
	else{
		if(a[k]<b[k]){
		
			return 1;
		}
		else{
			return -1;
		}
	}
}
	
void string_sort(char a[][MAX],int n){

	cout << "ok";
	for(int i=0;i<=n;i++){
		int index=i;
		for(int j=i;j<=n;j++){
		
			cout << "ok";
			int k=string_compare(a[index],a[j]);
			if(k=(-1)){
		
				index=j;
			}
		}
		string_swap(a[index],a[i]);
	}
}
		
			
			
int main(){

	int n;
	cin >> n;
	
	char a[n+1][MAX];
	for(int i=0;i<=n;i++){
		
		cin.getline(a[i],MAX);
	
	}cout << "ok";
	
string_sort(a,n);
	
	for(int i=0;i<n;i++){
	
		cout << a[i] << 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()


int main()
{

char A[15][12];
int i,j;
cin>>n1;
while (cin.getline(A[count++],12));

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){
    int i=0;
    while(true){
    
    if(s1[i]==0 && s2[i]==0) return 0;
    if(s1[i]==0) return 1;
    if(s2[i]==0) return -1;
    if(s1[i]<s2[i]) return 1;
    if(s1[i]>s2[i]) return -1;
    i++;
    }
return 0;
}


int main(){
    int n,i=0;
    cin>>n;
    struct strings ( char s1[n])    
    for(int i=0;i<n;i++){
        for(int j=0;j<12;j++){
        cin>>s1[i];
        }
    }
    while(i<n)
    (string_compare(s1[i],s1[i+1]))
    i=i+2;
    
    
    
    
    

}

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