Page 1 of 1

help me~ My codes got "Compile error". T_T

Posted: Mon Aug 29, 2005 5:29 pm
by ystoto
- first code -

Code: Select all

#include<iostream> 
#include<fstream> 
#include<vector> 
#include<algorithm> 
using namespace std; 

#ifndef ONLINE_JUDGE 
ifstream in("input.txt"); 
#else 
istream& in = cin; 
#endif 

typedef struct HLine{
	int beg, end;
	int height;
	bool direction;
} hLine;

typedef struct Cell{
	int minX, maxX;
	int minY, maxY;
	bool IorO;
} cell;

vector<hLine> lines;
vector< vector<cell> > ver;
vector<int> X;
vector<int> Y;
vector<int>::iterator Vitr;

bool lineCmp(hLine &a, hLine &b)
{
	if(a.height > b.height)
		return true;
	else if(a.height == b.height)
	{
		if(a.direction)
			return true;
		else
			return false;
	}
	else
		return false;
}

void inserting(vector<int> &a, int b)
{
	Vitr = find(a.begin(), a.end(), b);
	if(Vitr==a.end())
		a.push_back(b);
}

int main()
{
	int numOfCases, length, width, n, m;
	int i, j, k;
	int x, y, lastX, lastY, sum;
	hLine line;
	cell C;
	vector<cell> hor;

	while(in>>numOfCases)
	{
		in>>width>>length>>n;
		for(i=0;i<n;i++)
		{
			in>>m;
			in>>lastX>>lastY;
			inserting(X, lastX);
			inserting(Y, lastY);
			for(j=1;j<m;j++)
			{
				in>>x>>y;
				if(y==lastY)
				{
					line.beg = lastX;
					line.end = x;
					line.height = y;
					line.direction = (lastX < x) ? true:false;
					lines.push_back(line);
				}
				inserting(X, x);
				inserting(Y, y);
				lastX = x;
				lastY = y;
			}
		}
		inserting(X, 0);
		inserting(Y, 0);
		inserting(X, width);
		inserting(Y, length);

		sort(X.begin(), X.end());
		sort(Y.begin(), Y.end());
		sort(lines.begin(), lines.end(), lineCmp);

		for(i=0;i<Y.size()-1;i++)
		{
			for(j=0;j<X.size()-1;j++)
			{
				C.minX = X[j];
				C.minY = Y[i];
				C.maxX = X[j+1];
				C.maxY = Y[i+1];
				bool fl = false;
				for(k=0;k<lines.size();k++)
				{
					if(lines[k].height <= C.minY)
					{
						if(lines[k].direction)
						{
							if(lines[k].beg <= C.minX && lines[k].end >= C.maxX)
							{
								C.IorO = true;
								break;
							}
						}
						else
						{
							if(lines[k].end <= C.minX && lines[k].beg >= C.maxX)
							{
								C.IorO = false;
								break;
							}
						}
					}
				}
				if(k==lines.size())
					C.IorO = false;
				hor.push_back(C);
			}
			ver.push_back(hor);
			hor.erase(hor.begin(), hor.end());
		}

		sum=0;
		for(i=1;i<ver.size();i++)
		{
			for(j=ver[i].size()-2;j>=0;j--)
			{
				if(!ver[i][j].IorO)	
				{
					if(ver[i][j+1].IorO && ver[i-1][j].IorO)
					{
						ver[i][j].IorO = true;
						sum += (ver[i][j].maxX - ver[i][j].minX) * (ver[i][j].maxY - ver[i][j].minY);
					}
				}				
			}
		}
		cout<<sum<<endl;
	}	
	return 0;
}



- second code -

Code: Select all

#include<iostream> 
#include<fstream>
#include<string> 
#include<set> 
using namespace std; 

#ifndef ONLINE_JUDGE 
ifstream in("input.txt"); 
#else 
istream& in = cin; 
#endif 

typedef struct Seconda{ 
	string name; 
	set<int> pages; 
} seconda; 

struct cmp1 
{ 
	bool operator () (const seconda& a, const seconda& b) 
	{ 
		int i, minimum;
		string aa, bb;
		aa.assign(a.name.begin(), a.name.end());
		bb.assign(b.name.begin(), b.name.end());
		
		for(i=0;i<aa.size();i++)
		{
			if(aa[i] <= 90)
				aa[i]+=32;
		}
		for(i=0;i<bb.size();i++)
		{
			if(bb[i] <= 90)
				bb[i]+=32;
		}
		
		minimum = (aa.size() > bb.size()) ? bb.size() : aa.size();
		
		for(i=0;i<minimum;i++)
		{
			if(aa[i] > bb[i])
				return false;
			else if(aa[i] < bb[i])
				return true;
		}
		
		if(aa.size() > bb.size())
			return false;
		else
			return true;
	} 
}; 

typedef struct Primar{ 
	string name; 
	set<int> pages; 
	set<seconda, cmp1> seconday; 
} primar; 

struct cmp2 
{ 
	bool operator () (const primar& a, const primar& b) 
	{ 
		int i, minimum;
		string aa, bb;
		aa.assign(a.name.begin(), a.name.end());
		bb.assign(b.name.begin(), b.name.end());
		for(i=0;i<aa.size();i++)
		{
			if(aa[i] <= 90)
				aa[i]+=32;
		}
		for(i=0;i<bb.size();i++)
		{
			if(bb[i] <= 90)
				bb[i]+=32;
		}
		minimum = (aa.size() > bb.size()) ? bb.size() : aa.size();
		
		for(i=0;i<minimum;i++)
		{
			if(aa[i] > bb[i])
				return false;
			else if(aa[i] < bb[i])
				return true;
		}
		if(aa.size() > bb.size())
			return false;
		else
			return true;
	} 
}; 

string eachDoc, tmp; 
set<primar, cmp2> V; 
set<primar, cmp2>::iterator iitr;
int docNum=1; 


void findIndex() 
{ 
	int i, j, pageNum=1, sstart, woCnt; 
	string eachIndex, word[3]; 
	primar P;
	seconda S; 
	bool flagg=false; 
	
	while(true)
	{
		i=eachDoc.find(' ');
		if(i==-1)
			break;
		else
			eachDoc.erase(eachDoc.begin()+i);
	}
    
	for(i=0;i<eachDoc.size();i++) 
	{ 
		if(eachDoc[i]=='&') 
			pageNum++; 
		else if(eachDoc[i]=='{')  
			sstart=i+1; 
		else if(eachDoc[i]=='}')  
		{ 
			eachIndex = eachDoc.substr(sstart,i-sstart); 
			sstart=0; 
			woCnt=0; 
			for(j=0;j<eachIndex.size();j++) 
			{ 
				if(eachIndex[j]=='%' || eachIndex[j]=='$' || j==eachIndex.size()-1)
				{ 
					if(eachIndex[j]=='%') 
						flagg=true; 
					if(j==eachIndex.size()-1)
						word[woCnt] = eachIndex.substr(sstart, j-sstart+1); 
					else
						word[woCnt] = eachIndex.substr(sstart, j-sstart);
					sstart = j+1;
					woCnt++; 
				} 
			} 

			if(woCnt==1)
			{
				if(V.size() > 0)
				{
					for(iitr = V.begin(); iitr!=V.end(); iitr++) 
					{
						if(strcmp(&((*iitr).name[0]), &word[0][0])==0)
							break; 
					}
					
					if(iitr == V.end()) 
					{ 
						P.name.assign(word[0].begin(), word[0].end()); 
						P.pages.insert(pageNum); 
						V.insert(P);
						P.pages.erase(P.pages.begin(), P.pages.end());
					}
					else
						(*iitr).pages.insert(pageNum);
				}
				else
				{
					P.name.assign(word[0].begin(), word[0].end()); 
					P.pages.insert(pageNum); 
					V.insert(P);
					P.pages.erase(P.pages.begin(), P.pages.end());
				}
			} 
			else if(woCnt==2)
			{ 
				if(flagg)   //'%' 
				{ 
					set<primar, cmp2>::iterator itr; 
					for(itr = V.begin(); itr!=V.end(); itr++) 
					{
						if(strcmp(&(*itr).name[0], &word[1][0])==0) 
							break; 
					}
					if(itr == V.end()) 
					{ 
						P.name.assign(word[1].begin(), word[1].end()); 
						P.pages.insert(pageNum); 
						V.insert(P); 
						P.pages.erase(P.pages.begin(), P.pages.end());
					} 
					else 
						(*itr).pages.insert(pageNum); 
				} 
				else   //'$' 
				{ 
					set<primar, cmp2>::iterator itr; 
					for(itr = V.begin(); itr!=V.end(); itr++) 
					{
						if(strcmp(&(*itr).name[0], &word[0][0])==0) 
							break; 
					}
					if(itr == V.end()) 
					{ 
						P.name.assign(word[0].begin(), word[0].end()); 
						set<seconda, cmp1>::iterator itr2; 
						
						for(itr2 = P.seconday.begin(); itr2!=P.seconday.end(); itr2++) 
						{
							if(strcmp(&(*itr2).name[0], &word[0][0])==0) 
								break; 
						}
						
						if(itr2 == P.seconday.end()) 
						{ 
							S.name.assign(word[1].begin(), word[1].end()); 
							S.pages.insert(pageNum); 
							P.seconday.insert(S); 
							S.pages.erase(S.pages.begin(), S.pages.end());
							V.insert(P);
							P.seconday.erase(P.seconday.begin(), P.seconday.end());
						} 
						else 
							(*itr2).pages.insert(pageNum); 
					} 
					else 
					{ 
						set<seconda, cmp1>::iterator itr2; 
						for(itr2 = (*itr).seconday.begin(); itr2!=(*itr).seconday.end(); itr2++) 
						{
							if(strcmp(&(*itr2).name[0], &word[0][0])==0) 
								break; 
						}
						
						if(itr2 == (*itr).seconday.end()) 
						{ 
							S.name.assign(word[1].begin(), word[1].end()); 
							S.pages.insert(pageNum); 
							(*itr).seconday.insert(S); 
							S.pages.erase(S.pages.begin(), S.pages.end());
						} 
						else 
							(*itr2).pages.insert(pageNum); 
					} 
				} 
			} 
			else//3개 단어가 있을 때
			{ 
				set<primar, cmp2>::iterator itr; 
				for(itr = V.begin(); itr!=V.end(); itr++) 
				{
					if(strcmp(&(*itr).name[0], &word[1][0])==0) 
						break; 
				}
				if(itr == V.end()) 
				{ 
					P.name.assign(word[1].begin(), word[1].end()); 
					set<seconda, cmp1>::iterator itr2; 
					for(itr2 = P.seconday.begin(); itr2!=P.seconday.end(); itr2++) 
					{
						if(strcmp(&(*itr2).name[0], &word[2][0])==0) 
							break; 
					}
					
					if(itr2 == P.seconday.end()) 
					{ 
						S.name.assign(word[2].begin(), word[2].end()); 
						S.pages.insert(pageNum); 
						P.seconday.insert(S); 
						S.pages.erase(S.pages.begin(), S.pages.end());
						V.insert(P); 
						P.seconday.erase(P.seconday.begin(), P.seconday.end());
					} 
					else 
						(*itr2).pages.insert(pageNum); 
				} 
				else 
				{ 
					set<seconda, cmp1>::iterator itr2; 
					for(itr2 = (*itr).seconday.begin(); itr2!=(*itr).seconday.end(); itr2++) 
					{
						if(strcmp(&(*itr2).name[0], &word[2][0])==0) 
							break; 
					}
					if(itr2 == (*itr).seconday.end()) 
					{ 
						S.name.assign(word[2].begin(), word[2].end()); 
						S.pages.insert(pageNum); 
						(*itr).seconday.insert(S); 
						S.pages.erase(S.pages.begin(), S.pages.end());
					} 
					else 
						(*itr2).pages.insert(pageNum); 
				}
			}
		} 
	} 
} 

void printing() 
{ 
	cout<<"DOCUMENT "<<docNum++<<endl; 
	set<primar, cmp2>::iterator itr; 
	set<seconda, cmp1>::iterator itr2; 
	set<int>::iterator itr3; 
	for(itr=V.begin(); itr!=V.end(); itr++) 
	{ 
		cout<<(*itr).name; 
		for(itr3=(*itr).pages.begin(); itr3 != (*itr).pages.end() ; itr3++) 
			cout<<", "<<(*itr3); 
		cout<<endl; 
		for(itr2=(*itr).seconday.begin(); itr2!=(*itr).seconday.end(); itr2++) 
		{ 
			cout<<"+ "<<(*itr2).name; 
			for(itr3=(*itr2).pages.begin(); itr3!=(*itr2).pages.end();itr3++) 
				cout<<", "<<(*itr3); 
			cout<<endl; 
		} 
	} 
} 


int main() 
{
	char asg[] = "**";
	while(getline(in,tmp)) 
	{ 
		if(tmp.size()==1 && tmp[0]=='*') 
		{ 
			findIndex(); 
			printing(); 
			eachDoc.erase(eachDoc.begin(), eachDoc.end()); 
			V.erase(V.begin(), V.end()); 
		} 
		else if(tmp.size()==2 && strcmp(&tmp[0], asg)==0) 
			return 0; 
		else 
			eachDoc.append(tmp); 
	} 
	return 0; 
}

I can't to find it.
Please help me.

Posted: Mon Aug 29, 2005 7:08 pm
by Krzysztof Duleba
lineCmp, just as any other comparator, mustn't take references as arguments. Const references are fine, though.

set iterators are const iterators. You can't change an object once it's in a set.

Posted: Sun Nov 20, 2005 11:43 pm
by jjtse
did you get your compile problem resolved?

I'm having a compile error that is similar to yours. It compiles fine on my machine, but it doesn't compile on the judges machine. The only thing that I can think of that might have caused the compile error is that I used Vectors and I used a built in FIND function. It's the same find function taht you used here. I'm suspecting that might be the reason for the compile error.

Someone suggested that it might be the .clear() function used to clear vectors. I replaced that statement with something else, but it still didn't work.


How did you fix yours?

Posted: Mon Nov 21, 2005 1:32 pm
by Krzysztof Duleba
There are no Vectors or FIND in gcc. There are vectors and find, though.