It says compiler error

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
sklitzz
New poster
Posts: 32
Joined: Fri Dec 03, 2004 5:19 pm

It says compiler error

Post by sklitzz » Thu May 25, 2006 9:08 am

Could anyone tell me why this code doesn't compile.

Code: Select all

#include <iostream>
#include <algorithm>
#include <map>
#include <cstdio>
using namespace std;

int N, R;
map < string, int > ind;
int adj[200][200] = { false };

void floyd_warshall() {
	for( int k = 0; k < N; ++k )
		for( int j = 0; j < N; ++j )
			for( int i = 0; i < N; ++i )
				if( adj[i][k] != 0 && adj[k][j] != 0 ) {
					adj[i][j] >?= min( adj[i][k], adj[k][j] );
					//adj[i][j] = adj[j][i] = min( adj[i][j], adj[j][i] );
				}
}

int main() {
	int cnt = 1;
	
	scanf( "%d %d", &N, &R );
	while( !( N == 0 && R == 0 ) ) {
		int w, n = 0; 
		string s1, s2;
		
		memset( adj, 0, sizeof( adj ) );
		ind.clear();
 		for( int i = 0; i < R; ++i ) {
			cin >> s1 >> s2 >> w;
			
			if( ind.count(s1) == 0 ) ind[s1] = n++;
			if( ind.count(s2) == 0 ) ind[s2] = n++;
		
			adj[ind[s1]][ind[s2]] = adj[ind[s2]][ind[s1]] = w;
		}
		
		floyd_warshall();
		cin >> s1 >> s2;
		
		cout << "Scenario #" << cnt++ << endl;
		cout << adj[ind[s1]][ind[s2]] << " tons" << endl << endl;
				
		scanf( "%d %d", &N, &R );
	}
	
	return 0;
}

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Thu May 25, 2006 4:06 pm

string header file not included.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Thu May 25, 2006 4:29 pm

string header file not included, and this statement has a syntax error:

Code: Select all

               adj[i][j] >?= min( adj[i][k], adj[k][j] ); 
I am not sure what you are trying to do here, though my Visual C++ compiler complains but on the other hand, g++ compiler has no problems. Did you mean an assignment statement?

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Thu May 25, 2006 4:30 pm

string header file not included, and this statement has a syntax error:

Code: Select all

               adj[i][j] >?= min( adj[i][k], adj[k][j] ); 
I am not sure what you are trying to do here, but this is very weird: ">?=" operator? Though my Visual C++ compiler complains but on the other hand, g++ compiler has no problems :o . Did you mean an assignment statement? Can anyone explain?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Thu May 25, 2006 4:37 pm

It's a g++ extension.
x >?= y is same as: x = max(x, y)

User avatar
Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba » Thu May 25, 2006 4:50 pm

And it's depreciated (std::min/max are recommended) and quite slow.

sklitzz
New poster
Posts: 32
Joined: Fri Dec 03, 2004 5:19 pm

Post by sklitzz » Thu May 25, 2006 10:45 pm

I added the string header and got AC!
Thanks to you all.

Post Reply

Return to “C++”