Well, I'm trying to solve the following problem, and almost done: http://acm.pku.edu.cn/JudgeOnline/problem?id=1007
Here's my code:
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
/*
int compare(size_type pos1, size_type n1,
const charT* s, size_type n2 = npos) const;*/
int * sort(string *w, int n, int l, int * count){
for(int i = 0; i< n; i++){
for(int k= 0; k < l; k++){
for(int z = 0; z < k; z++)
if(w[k][z] > w[k][z]) count[i]++;
}
}
return count;
}
int main(){
cout << "Enter the number of strings, followed by the length of each one: " << endl;
int n,l;
cin >> n >> l;
int *count = new int[n];
string *s = new string[n];
for(int i =0; i < n; i++){
cout << "Enter the string #" << i+1 << endl;
cin >> s[i];
}
int * x = sort(s, n, l, count);
for(int i = 0; i < n; i++){
cout << x[i]<< endl;
}
getchar(); getchar();
}
I've no problem but the if condition line in sort(), and the I can't get the value of count correctly from sort()
Update: I just want you to find a suitable form for the if condition using the string subscript like the one above.