help with a problem

This is a discussion on help with a problem within the C++ Programming forums, part of the General Programming Boards category; Code: #include <string> #include <iostream> #include <conio.h> using namespace std; int main() { string name("HEEEELLLLPPPPP"); cout << name[7]; getch(); } ...

  1. #1
    aGp
    aGp is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    2

    help with a problem

    Code:
    #include <string>
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main()
    {
         string name("HEEEELLLLPPPPP");
         cout << name[7]; 
         getch();
         }
    Anny not null number may be represented with the Polish Notation ( Postfixed )
    , on those " numbers" {1, 2, 3 , .... , 10 } and operator * and +.
    Example , one of the representation of numer 13 is 8 5 + and other is 2 + 2 * 2 * 1 +.
    Longness of an representation includes all the caracters , inclusive spaces above any numer or operator , unless the final one.
    We say :
    Canonical representation ( the mos shortest representation described above . If exists more representations , then the shortes canonical representation is the
    shotest ( in lexicografhical mean ) .
    Describe an alghoritm for a nut null given number > 0 and returs his canonical
    representation in the system described above and calculate his complexity.

  2. #2
    aGp
    aGp is offline
    Registered User
    Join Date
    Jun 2006
    Posts
    2
    i have some clues on it , but ...
    recursive bactracink , traversing the three on his longness and pushing one by one in stack , or maybe a bunch and boud alghoritm.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    i might be wrong but wont you need to make an array first?

    Code:
    string name[15] = "heeeeelllllppp";
    
    cout << name[7];
    getch();
    i might be wrong as im a n00b and i aint even learned arrays properly yet. well, it might not be an array but it looks like one from what i know on C++ lol.

  4. #4
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    @Hugo716

    You obviously haven't come to strings yet - that's a class defined
    in <string> header which have lots of nice features over C style
    arrays of char, such as dynamic growth to fit the size of another
    such string, operator overloads and whatnot. Basically the
    code constructs an instance of a string and gives it an initial
    value of that string literal - it has nothing to do with arrays from
    the outside of the class, except that you can use array indices
    to access specific parts of the string. You should have a read up
    on strings - they're pretty cool - here's this sites intro

    @aGp

    Code - I can't speak for the rest of the people here, but I find this:

    Code:
    #include <string>
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main()
    {
         string name("HEEEELLLLPPPPP");
         cout << name[7]; 
         getch();
         }
    a little bit rude - especially the fact that it prints out only one
    character too - what's that about? This kind of behavior
    will just warrant flaming - only post code that is relevant to your
    problem, not some immature demand for help - that looks stupid.

    Spelling - I hope that English is not your first language, because
    in that case your poor literacy is excusable, but if it is, the post
    shows you to be very lazy.

    Question - Despite these conditions, I understand the topic of the
    post. But there is no question presented here:

    >>Describe an alghoritm for a nut null given number > 0 and
    returs his canonical representation in the system described
    above and calculate his complexity.

    This comes across as a demand - we don't respond to those - do
    your own work/homework - THIS IS NOT RENT-A-CODER

    At least show that you are willing to try, perhaps some sample
    code, or at least an idea of what you want to achieve, do you
    actually want to write this program, or is it a question on the
    theory of such an algorithm? I don't know, because you haven't
    given me any useful information, and I am certainly not going to
    take the time to research both (or either for that matter) for you.

    Come back with a real question, or don't bother coming back at all.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Postfix notation is NOT Polish" notation, but Reverse Polish notation. All you need to know about RPN here.

    And this problem seems a little complicated for a person of your level...
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    lol ok thank alot. hehe. ill check that page u said.

    i know u use arrays to get a part of a string, but i thought it was an array lmao, bet i looked really stupid. sorry.

    cheers, hugo.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21