Compile error in dcp-114

All general topics that Dev Skill members should discuss.

Compile error in dcp-114

by imran16 » Fri Oct 28, 2016 10:36 pm

I am getting this following compile error message for my code and i dont understand whats the problem.

/usercode/file.cpp:8:23: error: 'std::map > index' redeclared as different kind of symbol
map > index;
^
In file included from /usr/include/c++/4.8/cstring:42:0,
from /usr/include/x86_64-linux-gnu/c++/4.8/bits/stdc++.h:48,
from /usercode/file.cpp:2:
/usr/include/string.h:471:20: error: previous declaration of 'const char* index(const char*, int)'
extern const char *index (const char *__s, int __c)
^
/usercode/file.cpp: In function 'int main()':
/usercode/file.cpp:34:27: error: invalid types '[int]' for array subscript
index[take].push_back(counter2);
^
/usercode/file.cpp:58:42: error: invalid types '[int]' for array subscript
for(int k=0; k[int]' for array subscript
save2=index[save][k];
^
/usercode/file.cpp:72:14: error: 'index' does not have class type
index.clear();
^




Code: Select all

#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<ll>vi;
map<int,int>m;
map<int,int>::iterator it2;
map<int,vector<int> > index;

int n,t,number,counter=1,save,save2,take,take2,ans;
int main()
{
    scanf("%d",&t);
    for(int q=1; q<=t; q++)
    {
        counter=0;
        scanf("%d",&n);
        ll maxx=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&number);
            vi.push_back(number);
            m[number]++;
            maxx=max(maxx,number);
        }
        sort(vi.begin(),vi.end());
        ll counter2=0;
        for(it2=m.begin(); it2!=m.end(); it2++)
        {
            take=it2->first;
            take2=it2->second;
            while(take2--)
            {
                index[take].push_back(counter2);
                counter2++;
            }
        }
//        cout<<"INDEX PRINTING:\n";
//        for(it=index.begin(); it!=index.end(); it++)
//        {
//            take=(it->first);
//            cout<<"FOR "<<take<<":\n";
//            for(int i=0; i<index[take].size(); i++)
//            {
//                cout<<index[take][i]<<" ";
//            }
//            cout<<endl;
//        }
        ll len=vi.size();
        for(int i=0; i<len; i++)
        {
            for(int j=i+1; j<len-1; j++)
            {
                take=vi[i];
                take2=vi[j];
                save=take+take2;
                // cout<<"take= "<<take<<" take2= "<<take2<<" and save= "<<save<<endl;
                for(int k=0; k<index[save].size(); k++)
                {
                    save2=index[save][k];
                    // cout<<"index of "<<save<<"= "<<save2<<" and j = "<<j<<endl;
                    if(save2>j)
                    {
                        counter++;
                    }
                }
            }
        }
        printf("Case %d: %d\n",q,counter);
        vi.clear();
        m.clear();
        index.clear();
    }
    return 0;
}






 
Posts: 4
Joined: Sun Oct 23, 2016 7:02 am

Re: Compile error in dcp-114

by devskill » Mon Oct 31, 2016 8:37 am

can you try by changing the name "index" to something else? may be it is a reserved keyword or something that is conflicting.
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron