Oi.'s blog

By Oi., 13 years ago, In English

I'm not sure whether this is a known bug or not, but just in case:

I was wandering around the cities rankings (http://codeforces.net/ratings/cities), and when I tried to see the list of members from São Paulo by clicking on it, the system told me that city didn't exist.

I noticed it happens with and only with any city whose name contains diacritics: ´ ~ ^ etc
Examples:
http://codeforces.net/ratings/country/Poland/city/Gdańsk
http://codeforces.net/ratings/country/Brazil/city/São Paulo
http://codeforces.net/ratings/country/Brazil/city/Goiânia

(formatted like this for readability. You can also try http://codeforces.net/ratings/country/Poland/city/Gda%C5%84sk)

PS: The expected behavior is as follows: http://codeforces.net/ratings/country/Russia/city/Moscow

*Edit: Just realized that if you manually switch these characters, you can actually go to the right place! http://codeforces.net/ratings/country/Brazil/city/Sao Paulo ... maybe not too hard to fix :)


Full text and comments »

  • Vote: I like it
  • +34
  • Vote: I do not like it

By Oi., 14 years ago, In English
Think you can solve it :)? We all know it is expected that contradictory comparison functions may cause Runtime Error when used by the sort method. For instance, one could try sorting an array using a function that only returns True!

However, when seemingly equivalent procedures start giving different results, curiosity strikes!
Take this example:

struct number{
    int z;
    const bool operator< (const number &that) const{
        return z <= that.z;
    }
}numbers[10000];

int main (){
    for(int i = 0; i < 10000; i++){
        numbers[i].z = 2;
    }
    sort(numbers, numbers+10000);
    return 0;
}

Note the operator<  returns <=. In some cases this would cause a Runtime Error, such as if you replaced the
"numbers[i].z = 2;" line with something like "numbers[i].z = i%10;". But we will focus on this case, on which it does not result in error.

By now you must've noticed this struct basically simulates the sorting of an integer array, except for the <= comparison. So, one would expect an int array to behave similarly, when using a similar comparison function! Yet...

int array[10000];
const bool myfunc (int a, int b){
    return a <= b;
}

int main (){
    for(int i = 0; i < 10000; i++){
        array[i] = 2;
    }
    sort(array, array+10000, myfunc);   
    return 0;
}

If you try to execute this piece of code, although it inherently seems to be doing exactly the same as the one above, a Runtime Error will occur this time. Can you guess why? :)

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it