Wednesday, May 27, 2015

C言語で「1時間以内に解けなければプログラマ失格となってしまう5つの問題が話題に」の5問目を解いてみた

Java8で「ソフトウェアエンジニアならば1時間以内に解けなければいけない5つの問題」の5問目を解いてみた」と「Perl6で「ソフトウェアエンジニアならば1時間以内に解けなければいけない5つの問題」の5問目を解いてみた」経由。

以下のような問題ですね。
1,2,…,9の数をこの順序で、”+”、”-“、またはななにもせず結果が100となるあらゆる組合せを出力するプログラムを記述せよ。例えば、1 + 2 + 34 – 5 + 67 – 8 + 9 = 100となる
とてもいい問題だと思うし、一方で上の回答例がeval的な手法を使っていたので、そういうズルをせずに解いたらどうなるだろう、ということでCで書いてみた。

正解が出るようになるまでの所要時間、約30分。なんとかプログラマ合格のようです。
#include <stdio.h>

#define MAX_POS 9
#define EXPECTED 100

static char buf[32];

static void doit(int pos, int sum, char *p, int sign)
{
    int i, n, s;

    *p++ = sign == 1 ? '+' : '-';
    for (i = pos, n = 0; i <= MAX_POS; ++i, n *= 10) {
        *p++ = '0' + i;
        n += i;
        s = sum + sign * n;
        if (i == MAX_POS) {
            if (s == EXPECTED) {
                *p = '\0';
                printf("%s = %d\n", buf + 1, s);
            }
        } else {
            doit(i + 1, s, p, 1);
            doit(i + 1, s, p, -1);
        }
    }
}   

int main(void)
{
    doit(1, 0, buf, 1);
    return 0;
}

142 comments:

  1. Packers and movers @ http://professionalmovers.in/
    Packers and Movers Chennai@ http://professionalmovers.in/packers-and-movers-in-chennai/
    Packers and Movers Bangalore@ http://professionalmovers.in/packers-and-movers-in-bangalore/

    ReplyDelete
  2. I value the article.Really thank you! Much obliged
    Diwali wishes

    ReplyDelete
  3. Really appreciate you sharing this blog post. Want more.
    Happydiwaliwishess.in

    ReplyDelete
  4. Great, thanks for sharing this blog article.Really looking forward to read more. Will read on...
    childrens Day wishes 2015

    childrens Day quotes

    ReplyDelete
  5. I gathered useful information on this point . Thank you posting relative information and its now becoming easier to complete this assignment
    mahjong games | agar io | games like minecraft|halloween | pacman| kizi | hulk | geometry dash pc | sniper games | games

    ReplyDelete
  6. I really liked your blog post.Thanks Again. Really Cool.
    Dilwale torrent

    ReplyDelete
  7. I truly appreciate this blog article.Thanks Again. Cool.
    Dilwale movie download

    ReplyDelete
  8. I really enjoy the blog.Much thanks again. Really Great.
    New year wishes

    ReplyDelete
  9. I think this is a real great blog article.Much thanks again. Great
    New year wishes 2016

    ReplyDelete
  10. I am so grateful for your post.Much thanks again. Really Great.
    New year quotes 2016

    ReplyDelete
  11. I truly appreciate this blog.Much thanks again. Keep writing.
    happy new year images

    ReplyDelete
  12. Im grateful for the blog.Really thank you! Much obliged.
    shahrukh dilwale movie torrent

    ReplyDelete
  13. Great article.... Thanx a lot...
    For Tech related topic...
    Visit my site....
    TechVine

    ReplyDelete
  14. I was noticing from many days that your blog is helping too many readers as your articles are easy to understand and helpful to us.
    I think you should explore the articles on your website, You should also cover different different categories for articles as you writes awesome. Thanks for sharing this great article with us.
    Happy New Year 2016

    ReplyDelete
  15. This is a good idea, I would like to refer to my content development. I have a few concerns can not explain, hopefully this article can help me. baixar facebook gratis , baixar facebook , facebook gratis , descargar whatsapp messenger , descargar mobogenie gratis , download mobogenie , whatsapp messenger free

    ReplyDelete
  16. I have read your article several times. It really made me feel important, I think people would not ignore it. Thanks for sharing it. facebook gratis , facebook gratis , baixar whatsapp gratis , whatsapp apk , whatsapp plus , mobogenie baixar , android market

    ReplyDelete
  17. You Can Download new Apps and Games Download HikeFor Pc Plants vs Zombies 2 Free Download Download HikeSkins IDM SERIAL KEY FOR 2016
    wasap app
    wasap app
    wasap app
    wasap app
    wasap app
    You Can Download new Apps and Games Download HikeFor Pc Plants vs Zombies 2 Free Download Download HikeSkins IDM SERIAL KEY FOR 2016
    wasap app
    wasap app
    wasap app
    wasap app
    wasap app

    ReplyDelete
  18. Get details about LG G5 cases and Galaxy S7 cases..


    Galaxy S7 cases

    ReplyDelete
  19. Get Customer Care numbers,address and more details. Visit my site.

    ReplyDelete
  20. Euro cup is not far away. Click Euro Cup 2016 live" to watch euro cup live

    ReplyDelete
  21. Your posts really great. Every one is in-detailed and clear understanding. You are awesome.
    happy fathers day
    father's day 2016

    ReplyDelete
  22. Great article. I really appreciate the hard work you put in it. To know about Galaxy Note 7 Visit my blog.

    ReplyDelete
  23. http://clickymaza.pk/
    http://apkinmobile.com/
    https://jobs360.pk/
    http://paknulled.com/
    http://dramasalert.com
    http://euhpro.pk/

    ReplyDelete
  24. Badtameez Dill Watch All Dramas Colors TV Star Plus Zee TV Online Episodes

    ReplyDelete

  25. Hello! I just would like to offer you a huge thumbs up for your excellent info you've got right here on this post. I'll be coming back to your blog for more soon. Porus Drama

    ReplyDelete
  26. The great info shared by your blog as always. The Main Purpose of Your Article is about My Blog Super Ishq Pakeezah This Is the domain where you can Watch Online Zee TV Shows

    ReplyDelete
  27. Very nice Article good information Great post.Do you want to ask any queries related to your Yahoo from our experts will answer you in no time 2018,Zee TV If you really facing an issues in AOL emails service, for more information visit AOL.

    ReplyDelete
  28. lottery sambadToday Result: Lottery Sambad Result updated here on this page on the daily basis. As you know Sambad Lottery Draw held three times a day. You can check daily all results here from this page. Lottery Sambad one of the most famous and popular lottery around country. “Lottery Sambad Today” Result 11 ...

    ReplyDelete
  29. Ishq Pakeezah Online in High Quality Please visit at http://ishqpakeezah.com

    ReplyDelete
  30. Bepanah Drama is released and going well in TRP. This drama crossed all the trps in just 4 episodes. The review of this drama serial is good. and the strory line is much intersting and unique and from the start. No Single scene of this drama is boring. Bepanah Drama

    ReplyDelete
  31. Pinoy Channel global finance and culture center, and capital Washington, DC. Midwestern metropolis Chicago is known for influential architecture and on the west coast,Pinoy Lambingan Los Angeles' Hollywood is famed for filmmaking.

    ReplyDelete
  32. Desi Serials TV Box Full Episode Network. We exhibit top desi Serial channels broadcast online. Desi TV serial Ishqbaaz that are loved by desi people around the world. Watch them online. Porus Episode

    ReplyDelete
  33. Thank you,bepanah . Your registration is now complete. i like you page,bepanah.org

    You may now proceed to edit your Profile in order to fill in additional personal details about yourself But, or you could modify your Options to customize your browsing experience of this site. If you would rather do these things later, you can do so by following the links around the site to your User Control Panel.

    you can simply go back to the Forums and start posting in threads.

     

    ReplyDelete
  34. Thank you,kaleerein . Your registration is now complete. i like you page,

    You may now proceed to edit your Profile in order to fill in additional personal details about yourself But, or you could modify your Options to customize your browsing experience of this site. If you would rather do these things later, you can do so by following the links around the site to your User Control Panel.

    you can simply go back to the Forums and start posting in threads.

     
    You may now proceed to edit your Profile in order to fill in additional personal details about yourself But, or you could modify your Options to customize your browsing experience of this site. If you would rather do these things later, you can do so by following the links around the site to your User Control Panel.

    you can simply go back to the Forums and start posting in threads.

    ReplyDelete
  35. Tu Aashiqui is back again with new episode for the viewers so watch each episode with thrill again. The review of this drama serial is good. and the strory line is much intersting and unique and from the start. No Single scene of this drama is boring. Tu Aashiqui

    ReplyDelete
  36. wow this is wonderful post.Pinoy Tv network Brings Pinoy shows and i like your article always.
    You have a grip on this topic. We have to come daily to watch latest updates.
    i must say you will always rock like blogger. best Wishes.
    Pinoy TV Network

    ReplyDelete
  37. Watch all your favorite Sub Title shows online for free! Our website can provide you with free Eng Sub Full Episode of Subbed and Sub Korean tv.

    ReplyDelete
  38. Many thanks for sharing this info, I saved the site. I’m furthermore interested in information about leather sofa cleaning service, have you any idea the place where I could come across one thing like this? I will be back in a little while! pinoy lambingan teleserye

    ReplyDelete
  39. Best blog sharing a informative content.

    24 Oras

    ReplyDelete
  40. I read your article .It is really useful for Building wealth. All steps and tips are helpful for saving money .So we must follow your suggestion. Thank you so much for this information.also Watch LambinganTV Shows That Are Popular Pinoy Tambayan Replays And Pinoy Teleserye Of GMA TV At PINOYTV

    ReplyDelete
  41. Right here is the perfect webpage for anyone who would like to find out about this topic. You know so much its almost tough to argue with you (not that I really would want to…HaHa). You certainly put a new spin on a topic that's been discussed for decades. Great stuff, just great!
    MTV Kaisi Yeh Yaariyan
    Ishq Subhan Allah New Episodes

    ReplyDelete
  42. Watch online Indian Dramas Colors Tv , Star Plus , Sony Tv And Zee Tv


    Ishq Mein Marjawan

    naamkaran

    Maanga Hai Tujhe Rab Se

    ReplyDelete
  43. The next time I read a blog, I hope that it does not fail me just as much as this particular one. I mean, I know it was my choice to read, nonetheless I actually believed you would probably have something useful to talk about. All I hear is a bunch of whining about something you could fix if you were not too busy looking for attention.Araw Gabi

    ReplyDelete
  44. I have a great idea about the blog that I am thankful to the blog for you. Gurgaon Escort Photo Gallery

    ReplyDelete
  45. Even the call girls in Gurgaon are wearing dirndl. Please note the following here.
    Call Girl in Gurgaon
    Escort in Gurgaon
    Call Girl in Gurgaon

    ReplyDelete
  46. Celebrate and experience with our escort service in Gurgaon Celebrate in one of the many beer tents.
    Call Girl in Gurgaon
    Call Girl in gurgaon

    ReplyDelete
  47. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.Watch Yeh Pyaar Nahi Toh Kya Hai Full Episode Online

    ReplyDelete
  48. As a lady you accompany the gentlemen in public, be it a restaurant visit, a business lunch or a meeting.
    Male escorts Gurgaon

    ReplyDelete
  49. watch  Pinoy Tambayan online. latest all full episode filipino channel on tfcshows.com

    ReplyDelete
  50. Pinoy TV - Pinoy Tambayan - Pinoy Lambingan - Pinoy Channel - Pinoy Network. Filipino Channel online new today pinoy network on telesoap.com.

    ReplyDelete
  51. But would you rather go out for a bit before you go to the hotel? Then talk to our escort service in Hanover or even her lady.
    call girl in Gurgaon

    ReplyDelete
  52. Thanks for this wonderful post. The information in this article is very helpful to me. Thanks a lot for sharing. Keep blogging.
    Rishta Likhenge Hum Naya full episode

    ReplyDelete
  53. Pinoy Tambayan Live Pinoy Tambayan is another type of filipino TV shows because there are different terms for each of them so Pinoy Tambayan is also a famous Keyword and ASINTADO Pinoy Tambayan shows are also watched and loved by the people of Phillippines.

    ReplyDelete
  54. Muito boa a matéria. Aproveite e visite o melhor site Friv Jogos online para jogar totalmente grátis.

    ReplyDelete
  55. Pinoy TV Star: MAINE Mendoza Marks Her Third Anniversaryin the longest-running early afternoon assortment program in the nation, "Eat Bulaga," this July. She has advanced from the bashful Kalyeserye character Yaya Dub, to an unconstrained and connecting with have in the Sugod Bahay section of "Juan for All, All for Juan."

    ReplyDelete
  56. Dear ladies from Gurgaon of course, you can decide if you have time to accept such bookings.
    Russian escort in Gurgaon

    ReplyDelete
  57. But even here, there is a demand for call girls in pahipalpur.Escort in Mahipalpur

    ReplyDelete
  58. Your posts really great. Every one is in-detailed and clear understanding. You are awesome.
    Porus

    ReplyDelete
  59. Your Efforts are admirable.big thumbs up for your hard working this is very inforamtione i would like to thank you for this information.I really helps me alot

    kaun hai

    Today Bepanah

    Bepnanh

    woh apna sa

    yeh hai chahatein

    ReplyDelete
  60. Tempat / toko Beli sambungan pipa ini dimana yang lengkap di daerah jakarta, karena ada toko yg ga lengkap.
    Porus Drama

    ReplyDelete
  61. Our companion service is the best Gurgaon escort agency in the region which means that your gratification is definite.

    Escort in Manali

    ReplyDelete
  62. This is the right site for everyone who would like to find out about this topic. You realize so much its almost tough to argue with you (not that I actually would want to…HaHa). You definitely put a fresh spin on a topic which has been discussed for ages. Wonderful stuff, just great!
    https://dramaidea.com/

    ReplyDelete
  63. Aw, this was a very nice post. Taking the time and actual effort to produce a superb article… but what can I say… I procrastinate a whole lot and never manage to get anything done.

    https://pinoyako-tv.com

    ReplyDelete
  64. Hello there! I just want to offer you a big thumbs up for your great info you have right here on this post. I'll be coming back to your web site for more soon.

    Yeh Hai Chahatein Drama

    ReplyDelete
  65. Good Job Nail i agree with thats a new change toward the word. Hopes you would never mind this. As i appreciate you work. You are always welcome post.
    Isibaya

    ReplyDelete
  66. - These quotes, both popular and unknown, may prove to be inspiring, .... Such are the places where every man, woman and child seeks equal justice Children's Day in India rather are facilitators and instigators of self-directed learning by students.

    ReplyDelete
  67. https://watchonlineclub.com/mission-impossible-ghost-protocol-full-movie-2011-hollywood-watch-online.html

    ReplyDelete
  68. Please contact us to apply for our escort service jobs.
    Escort in Bhiwadi

    ReplyDelete
  69. Everyone loves it when individuals get together and share opinions. Great website, continue the good work!
    Ang Probinsyano

    Maalaala Mo Kaya

    ReplyDelete
  70. Way cool! Some extremely valid points! I appreciate you writing this write-up plus the rest of the site is also very good.
    Ishq Mein Marjawan

    Tu Aashiqu

    ReplyDelete
  71. Wow This post is wonderfull. I realy like it, Admin You always post amzaing things like that.
    Mzansi Magic

    ReplyDelete
  72. I am truly exceptionally glad to locate this specific site. I simply needed to say thank you for this enormous read!! I totally getting a charge out of each petite piece of it and I have you bookmarked to try out new substance you post Bepanah

    ReplyDelete
  73. Pinoy Tambayan, Pinoy Channel and Pinoy Ako. watch Pinoy Channel, Pinoy TV Replay and Pinoy Tambayan watch Pinoy Channel, Pinoy TV, Pilipinas Got Talent, Pilipinas Got Talent 6watch Pinoy TV Shows Free Pinoy TV Shows watch Pinoy Tambayan, Pinoy Channel, Pinoy TV Replay

    ReplyDelete
  74. Thanks Sir I was looking articles like that today I am so happy to find your webblog. Today I got quality of articles from your blog. I am looking forward to find more from your blog. Thanks for sharing your mind with us. Thanks again,please share my website ang probinsyano

    ReplyDelete
  75. I don't know if it's just me or if everyone else encountering problems with your blog.
    It appears as though some of the written text on your posts are running
    off the screen. Can somebody else please comment and let me know if this is happening
    to them too? This may be a issue with my internet browser because I've had this happen previously.
    Many thanks
    "http://dilhito.com

    ReplyDelete
  76. The blog is really informative and all the topic has discused in details i can see a lot of comments here that's only because of ur hardwork
    Kulfi Kumar Bajewala keep it up

    ReplyDelete
  77. Pinoy Tambayan is the platform where you can have on the best TV Shows having tons of entertainment which is not privided by Bacuit Archipelago which is known by its crystal white water and amazing atmosphere. watch Pinoy Tambayan Tv Shows. Heart touching acting involves the audience and they eagerly wait for Tambayan TV shows.

    ReplyDelete
  78. They are the best in the figure, boys can not control themselves after meeting our Mumbai Escorts girls. Even the other girls want to spend some time with our escorts girls. Every escort girl of our have their own speciality it means we have varieties, whatever your wish for,we can full fill with best escort matching to your requirement.

    Escorts Service in Mumbai
    Mumbai Escorts
    Female Escorts in Mumbai
    Escorts in Mumbai

    ReplyDelete
  79. Watch Online Movies & Free Download On
    https://123netflix.in/
    https://katmoviehd.live/
    https://movie2.info/
    https://9xmoviesonline.info/

    Watch Free Movies And TV Series

    https://katmoviehd.live/series

    https://katmoviehd.live/episode/

    https://katmoviehd.live/movies/

    ReplyDelete
  80. Watch bigg Boss 12 online without any charge at Bigg Boss 12 Watch Online

    ReplyDelete
  81. thanks due to the fact you have been precise-natured to percentage opinion subsequent to us. we are able to continually recognize all you have finished here because I understand you are selected worried thinking about our Bokul kotha Watch Online

    ReplyDelete
  82. This post is Very wonderfull. I realy like it
    This is Good work I Thanks to Admin and i Like your Post
    Ishq Mein Marjawan,
    Admin We Like Where Stars Land You always post amzaing things like that.
    We Would Like to give a suggestion work on daily basis.
    So That We Can get all updates daily. To get more info about your portal.

    Ishq Mein Marjawan

    ReplyDelete
  83. Kissasian download free and get update about latest drama releases in Sub Eng And IndoSub. Taiwanese, Chinese Kissasian series with subtitles are in English

    ReplyDelete
  84. Hey I like Your Post about Pinoy Lambingan Tv Shows. this website provide you with free PinoyTv Full Episode of pinoy tambayan and lambingan tv Su.well you always try to put good material.
    Lambingan Ofw
    Ang Probinsyano
    Halik
    Lambingan Su
    lambingan Tv
    ofw lambingan
    pinoy lambingan

    ReplyDelete
  85. watch online Pinoy Full Episode watch video, pariwikitv all pinoy dramas hd video, pinoy tambayan

    ReplyDelete
  86. Tomatometer And cinesilip rankings of the top 100 best TV shows of 2018 and all time. Lists of current TV series and award winners to help you figure out what to watch now.

    ReplyDelete
  87. For Online Cricket Match Streaming Visit

    http://www.cric.world/

    ReplyDelete
  88. watch ipl 2019 live
    watch ipl live
    watch ipl match live
    ipl 2019 live
    ipl 2019 live
    ipl 2019

    ipl live match
    ipl live streaming
    ipl 2019 live
    ipl 2019

    ReplyDelete
  89. Today result of lottery Sambad will be announced at 11 AM in the morning, 4 PM in the noon and 8 PM night. A person who plays India’s most popular lottery always look for the today result of lottery Sambad to get result on time. This helps in so many different ways whether the person won the lucky draw or lost.

    ReplyDelete
  90. So Here We are with the best and amazing Gunship Battle Mod Apk v2.7.25 Unlimited Money and this mod has some really amazing feature which will help you to enjoy the game with the more amazing way and this Gunship Battle Mod Apk is free to download by which you can also play with your friends.

    ReplyDelete
  91. Watch all your favorite pinoy Tambayan Tv shows online On http://pinoyflixtvs.com for free! Our website can provide you with free daily episodes of pinoy TV channel! Pinoy Tambayan basically consists of two words the Best word is Pinoy that means to introduce with the Philippines cultures and trend and the 2nd is Tambayan that refers to watch the online drams place for hangout. Pinoy Flix is providing you the facility to watch all the High Quality videos Pinoy Tambayan. All these videos are available with the better quality that one can have it. The use of Pinoy TV channels is increasing on a daily basis because the demands of people are also increasing so, it becomes necessary that issue such type of Pinoy channels that is likely by people for such purpose that people love to watch Pinoy Tambayan. All the latest updates of Pinoy TV-related are already uploaded on the site of Pinoy Channels so, that people can use it whenever they need. Watch all your favorite Pinoy Flix TV shows online for free

    ReplyDelete

  92. The Pinoy Ako makes available the best internet television for you, such that you are also able to browse through all the important stuff that you need with good ease. The way the platform is structured for you online, you have classified the different things that you may want to see or get to know about. This way, internet TV becomes not only very much accessible, but it also gets easier for you to use, as well as get what you need to know. Pinoy Tambayan is completely enjoyable, and it is good that you check it out yourself.
    If you need better online TV treatment, then Pinoy TV will serve you real good. With one website, you get all the directions that you need, to all that you need to see and know. This is, therefore, the best place for you to have the TV that you are I need of right here on the internet. If you are, ready for this, then log on to the website and see for yourself all the good that you can see on it.
    Indeed is Pinoy Ako the platform that you need and you can be sure that with it, there will be nothing else that you will want on other websites. It is a perfect online community for all, you should be a part of it, and enjoy every part of it. It is a great one, give it a shot.
    Click here to know more about TFC TV Live

    ReplyDelete
  93. 4. Defeat your insecurities of damaging your exquisite belongings when you are taking them from one place to another with the most prominent packing and moving service provider, Johnson Packers and Movers in Delhi. Offering all types of transfer services at a lower cost is the best company ever. For more information, visit our Johnson Packers and Movers official website today!

    Domestic Packers and Movers
    International Packers and Movers

    ReplyDelete

Note: Only a member of this blog may post a comment.