{"id":1229,"date":"2012-02-08T16:23:29","date_gmt":"2012-02-08T08:23:29","guid":{"rendered":"http:\/\/leybreeze.com\/blog\/?p=1229"},"modified":"2012-02-08T20:30:39","modified_gmt":"2012-02-08T12:30:39","slug":"go-for-it-1-%e4%ba%ba%e7%94%9f%e3%81%ae%e6%99%82%e8%a8%88","status":"publish","type":"post","link":"http:\/\/leybreeze.com\/blog\/?p=1229","title":{"rendered":"[ GO FOR IT ] 1) \u4eba\u751f\u306e\u6642\u8a08"},"content":{"rendered":"<p><strong>\u554f\u984c\uff1a<\/strong><\/p>\n<p>\u3042\u306a\u305f\u306e\u4e00\u751f\u309224\u6642\u9593\u306b\u305f\u3068\u3048\u308b\u3068\u4eca\u65e5\u306f\u4f55\u6642\u4f55\u5206\u4f55\u79d2\u3067\u3059\u304b\uff1f<br \/>\n\u305f\u3060\u3057\u3042\u306a\u305f\u306f\u3042\u306a\u305f\u306e\u8a95\u751f\u65e5(a\u5e74b\u6708c\u65e5)\u306e0\u6642\u3061\u3087\u3046\u3069\u306b\u751f\u307e\u308c\u3066n\u6b73\u307e\u3067\u751f\u304d\u308b(n\u6b73\u306e\u3068\u304d\u306f\u751f\u304d\u3066\u3044\u3066n+1\u6b73\u306b\u306f\u306a\u308c\u306a\u3044)\u3068\u3057\u3001b\u3068c\u306f\u4e00\u822c\u7684\u306a\u6708\u65e5\u306e\u7bc4\u56f2\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>i) 1990&lt;=a&lt;=2000,n=80\u306e\u3068\u304d\u3001\u4eca\u65e5\u306f\u4f55\u6642\u4f55\u5206\u4f55\u79d2\u3067\u3059\u304b\uff1f<br \/>\nii) 1900&lt;=a&lt;=2000,n=200\u306e\u3068\u304d\u3001\u4eca\u65e5\u306f\u4f55\u6642\u4f55\u5206\u4f55\u79d2\u3067\u3059\u304b\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff08C++\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\uff09\uff1a<\/strong><\/p>\n<pre lang=\"Cpp\">#include<cstdio>\r\n#include<cstdlib>\r\n#include<iostream>\r\n#include<ctime>\r\n\r\nusing namespace std;\r\n\r\n\/\/ check if the year is a leap year\r\nbool is_leap_year(int year)\r\n{\r\n\tif (year%4==0 && year%100!=0 || year%400==0)\r\n\t\treturn true;\r\n\telse\r\n\t\treturn false;\r\n}\r\n\r\n\/\/ check if the day is valid\r\nbool is_birthday_valid(int year, int month, int day)\r\n{\r\n\tswitch(month)\r\n\t{\r\n\tcase 1:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 2:\r\n\t\tif (is_leap_year(year))\r\n\t\t{\r\n\t\t\tif (day>0 && day<30)\r\n\t\t\t\treturn true;\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tif (day>0 && day<29)\r\n\t\t\t\treturn true;\r\n\t\t\telse\r\n\t\t\t\treturn false;\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 3:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 4:\r\n\t\tif (day>0 && day<31)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 5:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 6:\r\n\t\tif (day>0 && day<31)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 7:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 8:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 9:\r\n\t\tif (day>0 && day<31)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 10:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 11:\r\n\t\tif (day>0 && day<31)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\tcase 12:\r\n\t\tif (day>0 && day<32)\r\n\t\t\treturn true;\r\n\t\telse\r\n\t\t\treturn false;\r\n\t\tbreak;\r\n\t}\r\n\treturn true;\r\n}\r\n\r\n\/\/ calculate days after the given day, not including the given day (return 0 when given 12\/31)\r\nint calculate_days_after(bool leap, int month, int day)\r\n{\r\n\tint days=0;\r\n\tint days_of_month[]={31,28,31,30,31,30,31,31,30,31,30,31};\r\n\tif (leap)\r\n\t{\r\n\t\tdays_of_month[1]=29;\r\n\t}\r\n\tif (month<12)\r\n\t\tfor (int i=month;i<12;i++)\r\n\t\t{\r\n\t\t\tdays+=days_of_month[i];\r\n\t\t}\r\n\tdays+=(days_of_month[month-1]-day);\r\n\treturn days;\r\n}\r\n\r\n\/\/ calculate days before the given day, including the given day (return 366 when given a leap year's 12\/31)\r\nint calculate_days_before(bool leap, int month, int day)\r\n{\r\n\tint days=0;\r\n\tint days_of_month[]={31,28,31,30,31,30,31,31,30,31,30,31};\r\n\tif (leap)\r\n\t{\r\n\t\tdays_of_month[1]=29;\r\n\t}\r\n\tfor (int i=0;i<month-1;i++)\r\n\t\t{\r\n\t\t\tdays+=days_of_month[i];\r\n\t\t}\r\n\tdays+=day;\r\n\treturn days;\r\n}\r\n\r\n\/\/ calculate the number of years that are leap years between the startyear and endyear (including the startyear and endyear)\r\nint calculate_leap_year(int startyear, int endyear)\r\n{\r\n\tif (startyear<1904)\r\n\t{\r\n\t\tif (endyear>1903)\r\n\t\t\treturn (endyear-1904)\/4+1;\r\n\t\telse\r\n\t\t\treturn 0;\r\n\t}\r\n\telse if (is_leap_year(startyear))\r\n\t{\r\n\t\treturn (endyear-startyear)\/4+1;\r\n\t}\r\n\telse if (is_leap_year(startyear+1))\r\n\t{\r\n\t\treturn (endyear-startyear-1)\/4+1;\r\n\t}\r\n\telse if (is_leap_year(startyear+2))\r\n\t{\r\n\t\treturn (endyear-startyear-2)\/4+1;\r\n\t}\r\n\telse if (is_leap_year(startyear+3))\r\n\t{\r\n\t\treturn (endyear-startyear-3)\/4+1;\r\n\t}\r\n\treturn 0;\r\n}\r\n\r\n\/\/ calculate the total days in n years\r\nint calculate_total_days(int startyear, int n, int month, int day)\r\n{\r\n\treturn (n-1)*365+calculate_leap_year(startyear+1, startyear+n-1)+\r\n\t\tcalculate_days_after(is_leap_year(startyear),month,day)+calculate_days_before(is_leap_year(startyear+n),month,day);\r\n}\r\n\r\nint calculate_current_days(int startyear, int startmonth, int startday, int year, int month, int day)\r\n{\r\n\treturn (year-startyear-1)*365+calculate_leap_year(startyear+1, year-1)+\r\n\t\tcalculate_days_after(is_leap_year(startyear),startmonth,startday)+calculate_days_before(is_leap_year(year),month,day);\r\n}\r\n\r\nint main()\r\n{\r\n\t\/\/ declaration\r\n\tstruct tm *date;\r\n\ttime_t now;\r\n\tint year, month, day; \/\/ current time\r\n\tint birthyear,birthmonth,birthday; \/\/ birthday\r\n\tfloat total_days; \/\/ total days of n years\r\n\tfloat current_days; \/\/ total days since birthday\r\n\tint current_seconds; \/\/ time in 24 hours\r\n\tint current_minutes;\r\n\tint current_hours;\r\n\tint n; \/\/ life span\r\n\r\n\t\/\/ get current time\r\n\ttime(&now);\r\n\tdate = localtime(&now);\r\n\tyear = date->tm_year + 1900;\r\n\tmonth = date->tm_mon + 1;\r\n\tday = date->tm_mday;\r\n\r\n\t\/\/ input data\r\n\tint problemnum;\r\n\tcout<<\"Please input problem number(1-2):\"<<endl;\r\n\tdo\r\n\tcin>>problemnum; \/\/ select problem number\r\n\twhile(!(problemnum==1 || problemnum==2));\r\n\tif (problemnum==1)\r\n\t{\r\n\t\tn=80; \/\/ set life span\r\n\t\tcout<<\"Please input the year you birth(1990-2000):\"<<endl;\r\n\t\tdo\r\n\t\tcin>>birthyear; \/\/ get birthyear\r\n\t\twhile(birthyear<1990 || birthyear>2000);\r\n\t}\r\n\telse\r\n\t{\r\n\t\tn=200; \/\/ set life span\r\n\t\tcout<<\"Please input the year you birth(1900-2000):\"<<endl;\r\n\t\tdo\r\n\t\tcin>>birthyear; \/\/ get birthyear\r\n\t\twhile(birthyear<1900 || birthyear>2000);\r\n\t}\r\n\tcout<<\"Please input the month you birth:\"<<endl;\r\n\tdo\r\n\tcin>>birthmonth; \/\/ get birthmonth\r\n\twhile(birthmonth<1 || birthmonth>12);\r\n\tcout<<\"Please input the day you birth:\"<<endl;\r\n\tdo\r\n\tcin>>birthday; \/\/ get birthday\r\n\twhile(!is_birthday_valid(birthyear,birthmonth,birthday)); \/\/ check if the birthday is valid\r\n\r\n\t\/\/ calculate the result\r\n\tcurrent_days=calculate_current_days(birthyear,birthmonth,birthday,year,month,day); \/\/ calculate total days since birthday\r\n\ttotal_days=calculate_total_days(birthyear,n,birthmonth,birthday); \/\/ calculate total days of n years since birthday\r\n\tcurrent_seconds=(int)(current_days\/total_days*3600*24); \/\/ calculate the time in 24 hours\r\n\tcurrent_minutes=current_seconds\/60;\r\n\tcurrent_hours=current_minutes\/60;\r\n\tcurrent_seconds=current_seconds%60;\r\n\tcurrent_minutes=current_minutes%60;\r\n\r\n\t\/\/ output the result\r\n\tcout<<\"\u3042\u306a\u305f\u306e\u4e00\u751f\u309224\u6642\u9593\u306b\u305f\u3068\u3048\u308b\u3068\u4eca\u65e5\u306f  \"<<current_hours<<\":\"<<current_minutes<<\":\"<<current_seconds<<endl<<endl;\r\n\r\n\tsystem(\"PAUSE\");\r\n\treturn 0;\r\n}<\/pre>\n<p><strong>\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\uff1aLifeClock.cpp<\/strong><br \/>\nURL: http:\/\/leybreeze.com\/blog\/wp-content\/uploads\/2012\/02\/LifeClock.cpp<\/p>\n<p><strong>\u56de\u7b54\u3067\u304d\u305f\u554f\u984c\u306e\u51fa\u529b\uff1a<\/strong><br \/>\n\u5165\u529b\u306b\u3088\u3063\u3066\u9055\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e\u7c21\u5358\u306a\u8aac\u660e\uff1a<\/strong><br \/>\n\u751f\u5e74\u6708\u65e5\u3068\u73fe\u5728\u306e\u65e5\u4ed8\u3092\u53d6\u5f97<br \/>\n\u8a95\u751f\u65e5\u304b\u3089n\u6b73\u307e\u3067\u306e\u65e5\u6570\u3068\u8a95\u751f\u65e5\u304b\u3089\u4eca\u307e\u3067\u306e\u65e5\u6570\u3092\u8a08\u7b97<br \/>\n24\u6642\u9593\u306b\u5909\u63db<br \/>\n\u79d2\uff1a\u8a95\u751f\u65e5\u304b\u3089\u4eca\u307e\u3067\u306e\u65e5\u6570\/\u8a95\u751f\u65e5\u304b\u3089n\u6b73\u307e\u3067\u306e\u65e5\u6570*3600*24<br \/>\n\u79d2\u3092\u3088\u3063\u3066\u5206\u3068\u6642\u3092\u8a08\u7b97<\/p>\n<p><strong>\u5b9f\u884c\u65b9\u6cd5\uff1a<\/strong>LifeClock.exe\u3000\u5b9f\u884c\u3057\u3066\u5c0f\u554f\u306e\u756a\u53f7\u3068\u751f\u5e74\u6708\u65e5\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044<br \/>\nURL: http:\/\/leybreeze.com\/blog\/wp-content\/uploads\/2012\/02\/LifeClock.exe<\/p>\n<p><strong>\u5b9f\u884c\u74b0\u5883\uff1a<\/strong>Windows XP\/Vista\/7<\/p>\n<p><strong>\u30e9\u30a4\u30bb\u30f3\u30b9\uff1a<\/strong>GPLv3<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u554f\u984c\uff1a \u3042\u306a\u305f\u306e\u4e00\u751f\u309224\u6642\u9593\u306b\u305f\u3068\u3048\u308b\u3068\u4eca\u65e5\u306f\u4f55\u6642\u4f55\u5206\u4f55\u79d2\u3067\u3059\u304b\uff1f \u305f\u3060\u3057\u3042\u306a\u305f\u306f\u3042\u306a\u305f\u306e\u8a95\u751f\u65e5(a\u5e74b\u6708c &hellip; <a href=\"http:\/\/leybreeze.com\/blog\/?p=1229\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c[ GO FOR IT ] 1) \u4eba\u751f\u306e\u6642\u8a08\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[103],"_links":{"self":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1229"}],"collection":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1229"}],"version-history":[{"count":17,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1229\/revisions"}],"predecessor-version":[{"id":1247,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1229\/revisions\/1247"}],"wp:attachment":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}