Блог пользователя HitmanBBa

Автор HitmanBBa, 11 лет назад, По-английски

Hi everybody...

How are you ??

I have learnt a new move in c++ while reading an array, and I would like to share it with you my friends :).

Most of us while reading an array in contest he/she use this move:

int x[100005];
int i;
for(i=0;i<50;i++)
    scanf("%d", &x[i]);

We use &x[i] for point to the ith element in the array... look look look we just press shift + 7 and then write x[i]. oh that's make me so tired.

But look at this move...

int x[100005];
int i;
for(i=0;i<50;i++)
    scanf("%d", x+i); // I just press x + i only and for the same reason, that's make me comfortable. ^_^

If you got any lazy move like this please share it with us :).

Теги c++
  • Проголосовать: нравится
  • +13
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

If we speak about c++ and laziness cin >> x[i] is the answer

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

well i find this more lazy for(int i = 1 ; i <= n ; scanf("%d",arr + (i++)));

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

In C++ in library <cmath> you can use function hypot(double x, double y) to compute distence between 2-points instead of this code:

#include <cmath>

using namespace std;

double distence (double x, double y)

{

    return sqrt(x * x + y * y);

}
»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

You know when you have to print an M x N grid that is stored in an array?

for(int i = 0 ; i < m ; i++)
   for(int j = 0 ; j < n ; j++)
      cout << arr[i][j] << "\n"[j!=n-1];

It prints the elements with a space between them, and with an endline when j reaches n-1.

But sometimes the OJ doesn't recognize the space, so be careful.