Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance of "<?=" operator [duplicate]

I was looking through the solutions of a problem on Topcoder, and came across this one:

http://community.topcoder.com/stat?c=problem_solution&rm=249419&rd=9996&pm=6621&cr=309453

At present I am not interested to know how the algorithm works, but what's the usage of "< ?=" operator in the code? I tried compiling the code on my machine, and also on ideone.com, but to my surprise, the code fails to compile. What does the operator do, and why doesn't it work on standard compilers like ideone, and the code passes system tests on Topcoder?

The code is here:

using namespace std;

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

#define PB push_back
#define SZ size()
#define REP(v, hi) for (int v=0; v<(hi); v++)
#define REPD(v, hi) for (int v=((hi)-1); v>=0; v--)
#define FOR(v, lo, hi) for (int v=(lo); v<(hi); v++)
#define FORD(v, lo, hi) for (int v=((hi)-1); v>=(lo); v--)

typedef vector <int> VI;
typedef vector <VI> VVI;
typedef vector <VVI> VVVI;

/* ############################ THE REAL CODE ############################ */

class RoboRace {
  public:
  int startTime(vector <string> m, vector <string> _c) {
    string c;
    REP(i,_c.SZ) c+=_c[i];
    int N=c.SZ;
    int Y=m.SZ, X=m[0].SZ;
    VVVI best(Y, VVI(X, VI(N+1, 99999)));
    int ey=-1,ex=-1;
    int yy=-1,yx=-1;
    int fy=-1,fx=-1;
    REP(y,Y) REP(x,X) {
      if (m[y][x]=='Y') { yy=y; yx=x; m[y][x]='.'; }
      if (m[y][x]=='F') { fy=y; fx=x; m[y][x]='.'; }
      if (m[y][x]=='X') { ey=y; ex=x; m[y][x]='.'; }
    }
    REP(n,N+1) best[ey][ex][n]=n;
    REPD(n,N) REP(y,Y) REP(x,X) {
      if (m[y][x]=='#') continue;
      best[y][x][n] <?= best[y][x][n+1];
      if (c[n]=='N' && y>0)   best[y][x][n] <?= best[y-1][x][n+1];
      if (c[n]=='S' && y<Y-1) best[y][x][n] <?= best[y+1][x][n+1];
      if (c[n]=='W' && x>0)   best[y][x][n] <?= best[y][x-1][n+1];
      if (c[n]=='E' && x<X-1) best[y][x][n] <?= best[y][x+1][n+1];
    }

    REP(n,N) if (best[yy][yx][n] < best[fy][fx][n]) return n;
    return -1;
  }
};
like image 574
shivshnkr Avatar asked Feb 08 '14 21:02

shivshnkr


People also ask

What is meaning of === in PHP?

=== Operator: This operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.

What does 3 dots mean in PHP?

Meaning is that it decomposes an associative array to a list. So you do not need to type N parameters to call a method, just one. If method allows a decomposed parameter and if parameters are of the same type.

What does => mean in PHP array?

=> is the separator for associative arrays. In the context of that foreach loop, it assigns the key of the array to $user and the value to $pass .

What is the use of the symbol in PHP?

It makes PHP suppress any error messages (notice, warning, fatal, etc) generated by the associated expression. It works just like a unary operator, for example, it has a precedence and associativity.


1 Answers

That's a gcc extension, compound minimum operator, a binary operator that assign the minimum of its operands to the left-hand operand. It's mentioned in the deprecated features list of gcc manual.

A <?= B means assign the minimum of A and B to A.

There are (were) also

<?     minimum operator
>?     maximum operator
>?=    compound form of maximum operator

Sane code nowadays would use std::min instead.

like image 131
jrok Avatar answered Sep 17 '22 01:09

jrok