{"id":363,"date":"2018-11-15T22:30:30","date_gmt":"2018-11-15T14:30:30","guid":{"rendered":"https:\/\/blog.tcreopargh.xyz\/?p=363"},"modified":"2018-11-15T22:34:50","modified_gmt":"2018-11-15T14:34:50","slug":"c%e6%95%b0%e5%ad%97%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/blog.tcreopargh.xyz\/?p=363","title":{"rendered":"(C++)\u6570\u5b57\u5904\u7406"},"content":{"rendered":"\n<div class=\"mdui-panel mdui-panel-gapless\" mdui-panel>\n    <div class=\"mdui-panel-item mdui-panel-item-open\">\n      <div class=\"mdui-panel-item-header\">\n        <div class=\"mdui-panel-item-title\"><strong>\u95ee\u9898\u63cf\u8ff0<\/strong><\/div>\n        <i class=\"mdui-panel-item-arrow mdui-icon material-icons\">keyboard_arrow_down<\/i>\n      <\/div>\n      <div class=\"mdui-panel-item-body\">\n        <p>\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u4ece\u952e\u76d8\u8f93\u5165n\u4e2a\u975e\u96f6\u6574\u6570\uff080 &lt; n &lt;= 1000000000\uff09\uff0c\u5bf9\u6bcf\u4e2a\u6574\u6570n\u8fdb\u884c\u5982\u4e0b\u5904\u7406\uff1a\u5c06\u6574\u6570\u7684\u5404\u4f4d\u6570\u5b57\u53d6\u51fa\u6765\u76f8\u52a0\uff0c\u5982\u679c\u7ed3\u679c\u662f\u4e00\u4f4d\u6570\u5219\u8f93\u51fa\u8be5\u6570\uff0c\u5426\u5219\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\uff0c\u76f4\u5230\u5f97\u5230\u7684\u7ed3\u679c\u4e3a\u4e00\u4f4d\u6570\uff0c\u5e76\u8f93\u51fa\u8be5\u7ed3\u679c\u3002<\/p>\n      <\/div>\n    <\/div>\n  <\/div>\n\n\n\n<div class=\"mdui-panel mdui-panel-gapless\" mdui-panel>\n    <div class=\"mdui-panel-item mdui-panel-item-open\">\n      <div class=\"mdui-panel-item-header\">\n        <div class=\"mdui-panel-item-title\"><strong>\u8f93\u5165\u8bf4\u660e<\/strong><\/div>\n        <i class=\"mdui-panel-item-arrow mdui-icon material-icons\">keyboard_arrow_down<\/i>\n      <\/div>\n      <div class=\"mdui-panel-item-body\">\n        <p>\u591a\u7ec4\u6570\u636e\uff0c\u6bcf\u884c\u4e00\u4e2a\u6574\u6570\uff0c\u8f93\u5165\u4e3a0\u65f6\u8868\u793a\u8f93\u5165\u7ed3\u675f\u3002<\/p>\n      <\/div>\n    <\/div>\n  <\/div>\n\n\n\n<div class=\"mdui-panel mdui-panel-gapless\" mdui-panel>\n    <div class=\"mdui-panel-item mdui-panel-item-open\">\n      <div class=\"mdui-panel-item-header\">\n        <div class=\"mdui-panel-item-title\"><strong>\u8f93\u51fa\u8bf4\u660e<\/strong><\/div>\n        <i class=\"mdui-panel-item-arrow mdui-icon material-icons\">keyboard_arrow_down<\/i>\n      <\/div>\n      <div class=\"mdui-panel-item-body\">\n        <p>\u8f93\u51fa\u6bcf\u4e2a\u6574\u6570\u7684\u5904\u7406\u7ed3\u679c\uff0c\u7136\u540e\u6362\u884c\u3002&nbsp;<\/p>\n      <\/div>\n    <\/div>\n  <\/div>\n\n\n\n<div class=\"mdui-panel mdui-panel-gapless\" mdui-panel>\n    <div class=\"mdui-panel-item mdui-panel-item-open\">\n      <div class=\"mdui-panel-item-header\">\n        <div class=\"mdui-panel-item-title\"><strong>\u8f93\u5165\u6837\u4f8b<\/strong><\/div>\n        <i class=\"mdui-panel-item-arrow mdui-icon material-icons\">keyboard_arrow_down<\/i>\n      <\/div>\n      <div class=\"mdui-panel-item-body\">\n        <p>24\u00a0<br>39\u00a0<br>0\u00a0\u00a0<\/p>\n      <\/div>\n    <\/div>\n  <\/div>\n\n\n\n<div class=\"mdui-panel mdui-panel-gapless\" mdui-panel>\n    <div class=\"mdui-panel-item mdui-panel-item-open\">\n      <div class=\"mdui-panel-item-header\">\n        <div class=\"mdui-panel-item-title\"><strong>\u8f93\u51fa\u6837\u4f8b<\/strong><\/div>\n        <i class=\"mdui-panel-item-arrow mdui-icon material-icons\">keyboard_arrow_down<\/i>\n      <\/div>\n      <div class=\"mdui-panel-item-body\">\n        <p>6&nbsp;<br>3&nbsp; <\/p>\n      <\/div>\n    <\/div>\n  <\/div>\n\n\n\n<p>s\u4f7f\u7528c++\u7684string\u7c7b\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n\n<div class=\"codecolorer-container cpp default\" style=\"overflow:auto;white-space:nowrap;width:958px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/><\/div><\/td><td><div class=\"cpp codecolorer\"><span class=\"co2\">#include&lt;iostream&gt;<\/span><br \/>\n<span class=\"co2\">#include&lt;string&gt;<\/span><br \/>\n<span class=\"kw2\">using<\/span> <span class=\"kw2\">namespace<\/span> std<span class=\"sy4\">;<\/span><br \/>\n<span class=\"kw4\">int<\/span> main<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">while<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">true<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; string n<span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; getline<span class=\"br0\">&#40;<\/span><span class=\"kw3\">cin<\/span>,n<span class=\"br0\">&#41;<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span>n<span class=\"sy1\">==<\/span><span class=\"st0\">&quot;0&quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">break<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">else<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">while<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">true<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw4\">int<\/span> sum<span class=\"sy1\">=<\/span><span class=\"nu0\">0<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw4\">int<\/span> i<span class=\"sy1\">=<\/span><span class=\"nu0\">0<\/span><span class=\"sy4\">;<\/span> i<span class=\"sy1\">&lt;<\/span>n.<span class=\"me1\">size<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy4\">;<\/span> i<span class=\"sy2\">++<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sum<span class=\"sy2\">+<\/span><span class=\"sy1\">=<\/span>n.<span class=\"me1\">at<\/span><span class=\"br0\">&#40;<\/span>i<span class=\"br0\">&#41;<\/span><span class=\"sy2\">-<\/span><span class=\"st0\">'0'<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span>sum<span class=\"sy1\">&lt;<\/span><span class=\"nu0\">10<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">cout<\/span><span class=\"sy1\">&lt;&lt;<\/span>sum<span class=\"sy1\">&lt;&lt;<\/span>endl<span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">break<\/span><span class=\"sy4\">;<\/span> <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span> <br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">else<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw4\">char<\/span> <span class=\"sy2\">*<\/span>s<span class=\"sy1\">=<\/span><span class=\"kw3\">new<\/span> <span class=\"kw4\">char<\/span><span class=\"br0\">&#91;<\/span><span class=\"nu0\">1000<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">sprintf<\/span><span class=\"br0\">&#40;<\/span>s,<span class=\"st0\">&quot;%d&quot;<\/span>,sum<span class=\"br0\">&#41;<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n<span class=\"sy1\">=<\/span>s<span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw1\">continue<\/span><span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"kw3\">delete<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#93;<\/span>s<span class=\"sy4\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"br0\">&#125;<\/span> &nbsp; <br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"nu0\">0<\/span><span class=\"sy4\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>s\u4f7f\u7528c++\u7684string\u7c7b\u5b9e\u73b0\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a 12345678910111213141516171819202 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":302,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,7,32,10],"tags":[37,38],"_links":{"self":[{"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/posts\/363"}],"collection":[{"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=363"}],"version-history":[{"count":4,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions\/367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=\/wp\/v2\/media\/302"}],"wp:attachment":[{"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.tcreopargh.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}