-1

I observed this line in SnapDragon's solution in topcoder several times ret http://community.topcoder.com/stat?c=problem_solution&rm=166781&rd=5865&pm=3115&cr=272072. the above line appears on the 6th line from the bottom. Here is the code

   vector<string> tokenize(string s, string ch) { 
  vector<string> ret; 
  for( int p = 0, p2; p < s.size(); p = p2+1 ) { 
    p2 = s.find_first_of(ch, p); 
    if( p2 == -1 ) p2 = s.size(); 
    if( p2-p > 0 ) ret.push_back( s.substr(p, p2-p) ); 
  } 
  return ret; 
} 

vector<int> tokint(string s, string ch) { 
  vector<int> ret; 
  vector<string> p = tokenize(s, ch); 
  for( int i = 0; i < p.size(); i++ ) 
    ret.push_back( atoi(p[i].c_str()) ); 
  return ret; 
} 

vector<vector<int> > tokmat(vector<string> s, string ch) { 
  vector<vector<int> > ret; 
  for( int i = 0; i < s.size(); i++ ) 
    ret.push_back( tokint(s[i], ch) ); 
  return ret; 
} 

int pref[15][30]; 

class OrderFood { 
public: 
int selectEntrees(vector <int> a, vector <string> b) { 
  int i, j, k, x, y, z, n; 

  VVI t = tokmat(b, " "); 
  for( i = 0; i < t.size(); i++ ) 
  for( j = 0; j < t[i].size(); j++ ) 
    pref[i][t[i][j]] = 1; 
  n = a.size()/2; 
  map<VI, int> m; 
  for( i = 0; i < (1<<n); i++ ) { 
    VI v(t.size()); 
    for( j = 0; j < n; j++ ) if( i&(1<<j) ) 
    for( k = 0; k < t.size(); k++ ) 
      v[k] += pref[k][j]; 
    for( j = 0; j < t.size(); j++ ) if( v[j] > 2 ) break; 
    if( j < t.size() ) continue; 
    x = 0; 
    for( j = 0; j < n; j++ ) if( i&(1<<j) ) 
      x += a[j]; 
    if( m.count(v) ) 
      m[v] <?= x; 
    else 
      m[v] = x; 
  } 
  int n2 = a.size()-n; 
  int ret = 1000000000; 
  for( i = 0; i < (1<<n2); i++ ) { 
    VI v(t.size(), 2); 
    for( j = 0; j < n2; j++ ) if( i&(1<<j) ) 
    for( k = 0; k < t.size(); k++ ) 
      v[k] -= pref[k][j+n]; 
    for( j = 0; j < t.size(); j++ ) if( v[j] < 0 ) break; 
    if( j < t.size() ) continue; 
    x = 0; 
    for( j = 0; j < n2; j++ ) if( i&(1<<j) ) 
      x += a[j+n]; 
    if( !m.count(v) ) continue; 
    ret <?= x + m[v]; 
  } 
  if( ret == 1000000000 ) return -1; 
  return ret; 
} 
};
Hariprasad
  • 3,556
  • 2
  • 24
  • 40
Aditya Nambiar
  • 806
  • 1
  • 12
  • 22

2 Answers2

12

The <?= operator is a minimum operator, and the >?= is a maximum operator. Those both are nonstandard GCC Extensions. a<?=b is a=min(a,b). Use a=min(a,b) instead of this. It's much more readable, and works betters across platforms

scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
1

operator<?= is a GCC extension. In your example, it is setting ret to the minimum of ret and x + m[v].

This is not a standard operator and thus, is not portable to different compilers.

Zac Howland
  • 15,777
  • 1
  • 26
  • 42