CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
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(int &a,int  &b){
int temp=a;a=b;b=temp;}
void string_sort(char A[][12], int n,int &c)
{
    int i, j;
    for (i = 0; i < n - 1; i++)
    {
        // Last i elements will be in place after this for loop
        for (j = 0; j < n - i - 1; j++)
        {
            if (A[j][0] > A[j + 1][0])
               { swap(A[j], A[j + 1]);c+=1;}
		
        }
    }
}
int main(){
int n;
cin>>n;
char A[n][12];
for(int i=0;i<n;i++){
cin>>A[i];
A[i][11]='\0';}
int count=0;int c=0;
for(int i=0;i<n;i++){
for(int j=n-1;j>i;j--){
string_compare(A[i],A[j]);
count+=1;}
}
string_sort(A,n,c);
for(int i=0;i<n;i++){
cout<<A[n-1-i]<<" ";}
cout<<count<<endl;
cout<<c;}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

int  string_compare(char str[m],char str[n]){
}




















int main(){

int n;
cin>>n;
char str[n][MAX];
for(int i=0;i<n;i++){
	cin>>str[i];

}

}













































}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

void input(char *a, int n){
for (int i=0; i<n; i++) cin>>a[i];
}

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

int string_sort(char *a, int n, int& c){
int s=0;
for (int i=n; i>0; i--){
for (int j=0; j<i-1; j++){
c++;
if (int(a[j])<int(a[j+1])) {
int t = a[j];
a[j]=a[j+1];
a[j+1]=t;
s++;}
}}
for (int i=0; i<n; i++) cout<<a[i];
cout<<endl;
return s;	
}

int main(){

unsigned int n;
int c=0;
cin>>n;
char arr[10][n];
input(arr[1], n);
input(arr[2], n);
cout<<string_compare(arr[1],arr[2],n, c)<<endl;
int sw=string_sort(arr[1], n, c);
sw+=string_sort(arr[2],n, c);
cout<<"number of string_compare operations = "<<c<<endl;
cout<<"number of string swaps = "<<sw<<endl;
}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

using namespace std;

#define MAX 20

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 s[][MAX], int n, int &counter1, int &counter2)	
{
	int k=1; bool flag;
    	for (int i = 0; i < n-1; i++)
    	{
        	for (int j = 0; j < n-i-1; j++)
        	{
		counter1++;
		if(string_compare(s[j], s[j+1]) == 1) 
		{
		counter2++;
		swap(s[j], s[j + 1]);
		}
		
		for(int i=0; i<n-1; i++)
		{
			if(string_compare(s[j], s[j+1]) == 1) 
			{
			flag = 1;
			break;
			}
			
			else flag = 0;
        	}
        	if(flag) break;
    		}
    	if(flag) break;
    	}
}

int main()
{
	int n, count1=0, count2=0;
	cin >> n;
	
	char s[n][MAX];
	
	for(int i=0; i<n; i++)
	{
		cin >> s[i];
	}
	
	string_sort(s, n, count1, count2);
	
	for(int i=0; i<n; i++)
	{
		cout << s[i] << " ";
	}
	cout << endl;
	cout << count1 << " " << count2;
}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

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 x[][12], int n)
{
    int swap=0,compare=0,k;
    int i,j;
    for(i=0; i<n-1; i++)
    {
        for(j=0; j<n-i-1; j++)
        {
            k = string_compare(x[j],x[j+1]);
            if (k==0 || k==1 || k==-1) compare++;   // the compare will be used nC2 times
                                                    // therefore the answers in test cases are wrong 
            if(k==1)   
            {
                for ( int a=0; a < 12; a++)
                {
                    char temp= x[j][a];
                    x[j][a]=x[j+1][a];
                    x[j+1][a] = temp;
                }
                swap++;
            }
        }
    }
    for (int b=0; b<n; b++)
    {
        cout << x[b] << " ";   
    }
    cout << endl;
    cout << compare << " " << swap ;   // question asks about the no.of STRING
                                       // swaps not the total no.of swaps I chose to
                                        // swap the string by swapping element by element
                                        // so I musnt cout the total swaps but 
                                        // no.of STRING SWAPS 
}




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: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
int string_compare(char *first , char *second){
int 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){
 char temp =*a;
 *a=*b;
 *b=temp;
 }
void string_sort(char *A, int n){
int i, j ;
for(i=0; i<n-1; i++)
   {
    for(j=0; j<n-i-1; j++)
    {
     if(A[j]>A[j+1]){swap(&A[j], &A[j+1]);} 
    }
   }
for(i=0; i<n; i++){
                   cout<<A[i]<<" ";
                   cout<<endl;
                   }
                  
}
int main(){
char A[100][100];
int n; 
cin>>n;

for(int i=0; i<n; i++){
   for(int j=0; j<11; j++){
   cin>>A[i][j];
   }
   continue;
   }
string_sort(A[1], n);
}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<simplecpp>
int main(){
double ans1,ans2,x;
int n1,n2;
cin >> n1;
n2 = n1+1;
n1 = 0;
n2 = 0;
double A(n2);
for(int t=0; 'i' = <2; i++){
cin >> ('Ai');
}
cin >> x ;
for (int t = 0; t <= n2; i++){
ans2 + =(Ai)*pow(x,i); 
}
cout << ans1 << endl << ans2;
}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
#define MAX 100
using namespace std;
int string_compare(char *a,char *b)
{int i=0,r,j=0;
for(i=0;i<12;i++)
{if((int)a[i]>(int)b[i]){j==-1;break;}
if((int)a[i]<(int)b[i]){j==1;break;}}
return j;}
void swap(char *a,char *b)
{char t=*a;
*a=*b;
*b=t;}

void string_sort(char c[100][100],int n)
{int i,j,k,count=0;
	for(i=0;i<n-1;i++)
		{for(j=0;j<n-1;j++)
{k=string_compare(c[i],c[i+1]);count++;
if(j==-1){swap(&c[i],&c[i+1]);}
}}
for(i=0;i<n;i++)
{cout<<c[i]<<" ";}
cout<<count;}

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


}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

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

using namespace std;
int string_compare(char *first,char *second,int n){
int i = 0;
char fi =*first;
char se=*second;
//cout<<fi<<se;
while (true){
if (fi == 0 && se == 0) return 0;
if (fi == 0) return -1;
if (se == 0) return +1;
if (fi< se) return -1; //cout<<"Prob";}
if (fi > se) return +1;
i++;
}
return 0;
}

void string_reverse(char* A){
int L = 0;
while (A[L] != '\0') L++;
int n = L;
//cout<<"0"<<A[0];
//cout<<A[1]<<"1";

//for(int i=0;i<n;i++) rev_s[n-1-i] = s[i];
int i, j;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
        	char temp;
            if (A[j] > A[j + 1])

                temp=A[j];
            	A[j]=A[j + 1];
            	A[j+1]=temp;
            	//cout<<A[j]<<A[j+1]<<temp<<endl;
            	            //	cout<<A[j]<<endl;
        }
    } 
//rev_s[n] = 0; // what will happen if you did not include this statement?
}




int main(){
	int n;
cin>>n;
char A[11][15];
char B[11][15];

//input from user
cin.getline(A[0],11);
for(int i=0;i<n;i++){
//cout<<i+1;
cin.getline(A[i],11);
}
int ctr=0;
for (int i=0;i<n-1;i++){ // j bhi ghusa denge 
char *first=A[i];
char *second=A[i+1];
//cout << *first << *second;
cout<<string_compare(first,second,n);
ctr=ctr+ctr+1;
}
//for(int i=0;i<n;i++){
//cout<<A[i]<<endl;
//}

//for (int i=0;i<n;i++){ // j bhi ghusa denge 
//char *first=A[i];
//cout << *first << *second;
//string_reverse(first);




//printing output
for(int i=0;i<n;i++){
cout<<endl<<A[i]<<endl;
}
cout<<"number of comparison"<<ctr;

}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

1. A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in augmented alphabetical order, -1 if the second string appears before the first in augmented alphabetical order, and 0 if the two strings are equal to each other. 

2. A function string_sort which sorts the character strings in reverse alphabetical order using the bubble-sort algorithm.Your program should also print the number of string_compare operations (i.e., how many times the string_compare routine was called) and the number of string swaps performed.

Constraints
n is a positive integer, n < 15

The maximum length of any of the strings should be 11, excluding the NULL character

The character strings should contain only lower case alphabets

Student submission:
#include<iostream>
using namespace std;
#define MAX 100
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++;
}
cout<<i;
return 0;
}
void string_copy (char *dest,  char* source) {
	int i;
	for(i=0;source[i]!= '\0';i++){
		dest[i] = source[i];
	}
	dest[i] = source[i];
	}

void myswap (char*s1, char* s2){
char *temp;
string_copy (temp, s1);
string_copy (s1, s2);
string_copy (s2, temp);
}

void bubblesort (char s[][12], int n){
  int i, j;
    for (i = 0; i < n - 1; i++)
    {
        // Last i elements will be in place after this for loop
        for (j = 0; j < n - i - 1; j++)
        {
		string_compare (s[j], s[j+1]);
		int q=0;
		if (string_compare (s[j], s[j+1])==-1) {
                myswap(s[j], s[j + 1]);
		q++;
		}
		cout<<q;
        }
    }
}


int main(){
int n;
cin>>n;
char s[n][12];
for (int i=0; i<n; i++){
cin.getline(s[i], 12);
}
bubblesort (s, n);
for (int i=0; i<n; i++){
cout<<s[i];
} 
}

Grading criterion: Quality and number of comments.
Rating A: Well Commented
Rating B: Ok Commented
Rating C: Poor or No Comments
Rating D: 0
Assigned grade: C