Yup, it's quite simple.
I bet you write something like this:
----------------------------------------------------
// e.g. 1
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i < 10; i++)
cout << i << endl;
return 0;
}
----------------------------------------------------
That will do, but kind of cliche.
Then how's the following code?
----------------------------------------------------
// e.g. 2
#include <iostream>
#define forf(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
int main() {
forf (i, 10)
cout << i << endl;
return 0;
}
----------------------------------------------------
What do you think? Guess it depends.
But the source above saves you a lot of time especially when it comes to programming contests demanding speedy conding!!
In the same way, you can utilize the macro below:
#define forb(i, n) for(int i=(int)(n)-1; i >= 0 ; i--)
0 件のコメント:
コメントを投稿