Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Friday Programming Quiz

Friday Programming Quiz

Scheduled Pinned Locked Moved The Lounge
csharpasp-netcomtutorial
24 Posts 15 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Eytukan
    vector<int> vec_num;
    for(int i=1;i<argc;i++){
     vec_num.push_back(atoi((char*)argv[i]));
    }
    sort(vec_num.begin(),vec_num.end());
    copy(vec_num.begin()+((vec_num.size()-5)/2),
    vec_num.end()-((vec_num.size()-5)/2), ostream_iterator<int>(cout, "\n"));
    

    The Advantage in work-from-home is that... we can blame the dog -Mark Salsbery Best wishes to Rexx[^]

    R Offline
    R Offline
    Rama Krishna Vavilala
    wrote on last edited by
    #21

    5 for using the ostream_iterator alone:)

    Co-Author ASP.NET AJAX in Action

    E 1 Reply Last reply
    0
    • R Rama Krishna Vavilala

      5 for using the ostream_iterator alone:)

      Co-Author ASP.NET AJAX in Action

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #22

      Anyway, a 5 is a 5 ;P. Btw I think I should learn a new language to reply to your Friday Question. Replies representing all other languages are just there in seconds you post your question.we can't make our replies unique unless I try for a deliberately different technique of the same language.:-D


      The Advantage in work-from-home is that... we can blame the dog -Mark Salsbery Best wishes to Rexx[^]

      1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        Given a set of numbers passed to the command line. The number of number is always odd. The program should sort them and output the 5 numbers in the middle. For example, if there are 9 numbers the output should be sorted numbers from indices 2 to 6. e.g.

        c:> med5 67 89 12 1 8 1 3 5 7
        3
        5
        7
        8
        12

        Full marks to a VB.NET 9.0 solution.;)

        Co-Author ASP.NET AJAX in Action

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #23

        Here's some C#.

        System.Collections.Generic.List<int> list = new System.Collections.Generic.List<int>
        (
        System.Array.ConvertAll<string,int>
        (
        args
        ,
        delegate ( string s ) { return ( (int) System.Convert.ChangeType ( s , typeof(int) ) ) ; }
        )
        ) ;

        list.Sort() ;

        foreach
        (
        int i
        in
        list.GetRange
        (
        args.Length/2-2
        ,
        5
        )
        )
        {
        System.Console.WriteLine ( i ) ;
        }

        This points up two shortcomings of the current (V2) implementation of .net: 1) System.Array doesn't have a GetRange() method 2) Sort() returns void -- returning a reference to the object would be more flexible If these shortcomings were corrected, the above code could be:

        foreach
        (
        int i
        in
        System.Array.ConvertAll<string,int>
        (
        args
        ,
        delegate ( string s ) { return ( (int) System.Convert.ChangeType ( s , typeof(int) ) ) ; }
        ).Sort().GetRange
        (
        args.Length/2-2
        ,
        5
        )
        )
        {
        System.Console.WriteLine ( i ) ;
        }

        -- modified at 16:33 Saturday 1st September, 2007 Whoops, forgot to protect the angle-brackets -- modified at 16:34 Saturday 1st September, 2007 And then of course I put them backward

        1 Reply Last reply
        0
        • P PIEBALDconsult

          Not Vaporware Beta? :-D As VB is just a "prototyping language", it makes sense to use it as a test bed for Linq, before putting the final implementation in C#.

          B Offline
          B Offline
          Besir Kasami
          wrote on last edited by
          #24

          Do you now that the Silverlight Compiler is written in VB.Net???? You should think twice before you say that VB is used only for testing purposes.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups