Thread: three

  1. #1
    Registered User
    Join Date
    Aug 2011


    Hello guys!

    I've tried to solve the next problem:
    For a sequence of natural numbers n you must establish the maximum number of elements of the sequence whose sum divides 3 and the items that don't belong the sum.
    So,I need a variable n(for the number of numbers that will be read),nr(for the number I read at the current step),i,s3(that is initially 0) and a counter that counts the maximum items of the sequence whose sum divides 3.
    How should I do it?
    int n,i,nr,s3 = 0,k3 = 1;
    	cin >>  n;
    	for (i = 1;i <= n;i++) {
    	cin >> nr;
    	s = s+nr;
    	if (s % 3 == 0) break; // What should I do here ??
    Thanks in advance !!

  2. #2
    Registered User
    Join Date
    Nov 2011
    First of all I will recommend in the future to use more explanatory title.
    Second, the problem is much more difficult than you are trying to solve in the code.
    e.g. lets say n=10, then your solution doesn't take into consideration the 1,3,4,7 solution because you don't allow skipping numbers.
    This is valid only if I understood the problem.
    I believe it should at least be loop inside loop.
    And you probably need some data structure to hold the current used inumbers.

  3. #3
    Registered User
    Join Date
    Oct 2006
    I'm nominating this thread for the "worst thread title of the year" award.

  4. #4
    Registered User
    Join Date
    Aug 2011
    Quote Originally Posted by Elkvis View Post
    I'm nominating this thread for the "worst thread title of the year" award.
    I am sorry to disappoint you but this is not the title I chose for the problem.I found this problem in a book a couple of weeks ago and this was its name 'three'.What is so wrong with it? Maybe it doesn't say much about the problem but I kept the name without realising when I wrote the thread.
    Next time I will try to give my threads better titles so you all can understand...

  5. #5
    Join Date
    Oct 2007
    Inside my computer
    The title should describe what the topic of the thread is about.
    More suited names might have been "I need help with this algorithm" or "help with natural number algorithm," etc.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed