Thread: C++ Primer 4th Edition, Problem with Exercise

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    19

    C++ Primer 4th Edition, Problem with Exercise

    Hey, I've searched online for answers to these exercise problems for forever, but I just couldn't find it. Anyways, I have problems with exercises 1.24. I just don't get it. I don't even know how to start it, actually. And could someone explain to me, how do I input several books without telling the program exactly how many I am putting in?

    Thanks for any help.

    -Kai

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    Yeah....heh. Sorry guys! Oh, I've got another question though. How is i t that I input a negative number? the minus sign doesn't work...I think.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    You need to call the support guys for your computer and have them fix the minus sign...

    ... Or you can be more specific in your question and avoid silly answers like the one I just gave you.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    how do I input several books
    You can type them in by hand, or hire a few trillion servile monkeys to do it for you. You might want to check if the books have already been typed into digital form in your local digital library, to save yourself the effort. Alternatively, scan the pages in and use OCR software or send input as images. The books should then come in machine-readable format.

    without telling the program exactly how many I am putting in
    If you have in your possession a Turing machine, memory constraints shouldn't be a problem. You may want to implement a compression routine in any case, though, to be on the safe side.

    On the other hand, the amount of all printed material in the world is estimated to be around 200,000,000 GB, so plugging in 400000 500 GB IDE hard disks should be enough for most practical purposes.

    For convenience, I recommend you use std::string.
    Last edited by jafet; 07-15-2006 at 12:33 PM.
    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;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  3. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  4. new to c. problem with exercise.
    By cakewalkr7 in forum C Programming
    Replies: 4
    Last Post: 04-21-2002, 08:37 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM