affix's blog

By affix, 13 years ago, In English
Hi everyone.
i was accepting some easy problems and reading peoples code in solution size order.
and in most problems C++ was not best language and vice versa when i was reading solutions in harder problems C++ was  better than other languages in solution size.
what do you think about this?
which language is winner?
  • Vote: I like it
  • -9
  • Vote: I do not like it

13 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

IMHO, the language does not matter much (if this language does not require you to implement hashmaps, lists, qsorts, priority queues etc manually). If you know C++ libraries well - use it, if not - you may optionally learn java.

I've started training in TC and later CF with the only goal - to practice java. Before that I was programming mainly in C, for about 10 years. My knowledge of C++ stl was extremely weak, but java API provide a great comfort to me.

For TC any problem could be solved in java, since problemsetters write reference solutions in it. I do not know how about CF, but it seems that the only case to prefer C++ is when you are trying some inefficient solution and want to run it as fast as possible. In other cases you find that C++ and java provide very similar abilities, but with C++ you need to be more accurate and attentive. (However if you have great experience with C++, the idea of changing language to java would not be adequate)

For simplest problems also you may want to use perl or python, which allow you some economy of time (if you do not use code templates).

Also java/python/perl is preferable for those rare problems when you may want to use regexps.

  • 13 years ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    a thousand of imps, please, rewrite this code in Java using notepad as IDE:

    #include <iostream>
    int main()
    {
        long long sum = 0, x = 0;
        while (cin>>x, x)
            sum += x;
        cout<<sum;
    }

    • 13 years ago, # ^ |
      Rev. 2   Vote: I like it +5 Vote: I do not like it

      By the way your code yields compile errors: "cin, cout were not declared in this scope" I shall use comment-editing field right here "as an IDE":


      public class AnonimousTest {
      public static void main(String... args) {
      java.util.Scanner in = new java.util.Scanner(System.in);
      long sum = 0, x = 0;
      while ((x = in.nextInt()) != 0) {
      sum += x;
      } // while
      System.out.println(sum);
      } // main
      } // class AnonimousTest
      Well, I've made idiotic mistake too - see the previous edition.
      • 13 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        Now if you are ready for challenge, provide shortest solution in C++ for the problem 118A, for example.
        • 13 years ago, # ^ |
          Rev. 3   Vote: I like it +6 Vote: I do not like it


          #include <iostream>
          #include <string>
          #include <sstream>
          using namespace std;
          
          const string a_thousand_of_imps = "aoyeui";

          int main() { string s; cin>>s; strlwr((char*)s.c_str()); while (s.find_first_of(a_thousand_of_imps) != -1) s.erase(s.find_first_of(a_thousand_of_imps), 1); for (int i=0;i<(int)s.length();i++) cout << "." << s[i]; return 0; }
          • 13 years ago, # ^ |
            Rev. 2   Vote: I like it 0 Vote: I do not like it

            Thank you for accepting this excercise!
            Now let us examine another approach:

            (thousand devils with this "unclosed math text" - here is a link to solution)


            I am not ready to judge which approach is worse. Surely this regexp-work could be expressed even shorter in python/perl, but not many judges allow them...
    • 8 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How are you done darlin after all these years

13 years ago, # |
  Vote: I like it +10 Vote: I do not like it
Solution size is a bad metric to be honest.