jeudi 30 juin 2016

Here strcmp() don't work. why?

I just compared with string a and b. But why did I get compiler error ? Have any limitation here to compare with string by strcmp() ?

#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    string ar,a,b;
    while(scanf("%d",&n) != EOF){
        if(n == 0) break;
        for(int i = 0; i < n; i++){
            cin>>ar[i];
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                a = ar[i] + ar[j];
                b = ar[j] + ar[i];
            }
            if(strcmp(a,b) < 0){
                swap(a,b);
            }
        }
        cout<<a[0];
        printf("\n");
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire