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

Автор OtterZ, история, 13 месяцев назад, По-английски

In fact,I don't want to use this to detect LLMs,but it's very important to say that because something wrong might happen if you don't do that.

In fact when I trying to find a mistake in a code,I saw:

for(int i = 1; i <= n; i ++){
	if(p[i].x > p[i - 1].x)
		if(p[i - 1].x != 0)
			f2 ++;
	else{
                dt2 ++;
		if(!gt[dt2 + cnt1])
			f2 ++;
	}
}

And found the code with same result is this:

for(int i = 1; i <= n; i ++){
	if(p[i].x > p[i - 1].x){
		if(p[i - 1].x != 0)
			f2 ++;
	        else{
                        dt2 ++;
		        if(!gt[dt2 + cnt1])
			        f2 ++;
	        }
        }
}

This will lead to WA and make you cost a long time to find mistake.So please write like this:

for(int i = 1; i <= n; i ++){
	if(p[i].x > p[i - 1].x){
		if(p[i - 1].x != 0){
			f2 ++;
                }
        }
	else{
                dt2 ++;
		if(!gt[dt2 + cnt1]){
			f2 ++;
                }
	}
}

To make sure the structure is right.

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

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

I recommend using -Wall -Wextra, it catches this structure when you have if if else without curly brackets. It's actually quite useful in general, because in CP you can just ignore the stupid warnings about signedness and such, and it catches silly mistakes like this for you.

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

I don't think any LLM writes a code without strict {}s.

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

CPers, and their disdain for code formatters.

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

I learnt this the hard way. Ever since, I've been using braces for each structure I open.

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

So I am an LLM! I usually write code without the curly brackets after the if statement, but I was aware of this error beforehand, and I have always managed to work around it. Anyway, thanks for the note brother

Not important
»
13 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Ig its pretty common, the else is matched with the nearest if in the same scope or block. Few textbooks call this dangling else.