【结果填空】 (满分5分) 1949年的国庆节(10月1日)是星期六。 今年(2012)的国庆节是星期一。 那么,从建国到现在,有几次国庆节正好是星期日呢? 只要答案,不限手段! 可以用windows日历,windows计算器,Excel公式,。。。。。 当然,也可以编程! 不要求写出具体是哪些年,只要一个数目! 千万不要提交源代码! 答案不要写在这里,写在“解答.txt”中
有趣的题目,我就来有趣的搞一下 首先linux下 date命令可以查看当前时间
$ dateWed Feb 8 21:04:26 CST 2017拿有没高级用法呢
$ man date发现的
-d, --date=STRING display time described by STRING, not 'now' %x locale's date rePResentation (e.g., 12/31/99)试一下
$ date -d "10/01/1949"Sat Oct 1 00:00:00 CST 1949可以,很强 然后用System的命令
#include <bits/stdc++.h>using namespace std;int main(){ for (int i = 1949; i <= 2012; i++) { stringstream ss; ss << i; string s; ss >> s; string cmd = "date -d 10/01/" + s; system(cmd.c_str()); }}得到输出
Sat Oct 1 00:00:00 CST 1949Sun Oct 1 00:00:00 CST 1950Mon Oct 1 00:00:00 CST 1951Wed Oct 1 00:00:00 CST 1952Thu Oct 1 00:00:00 CST 1953Fri Oct 1 00:00:00 CST 1954Sat Oct 1 00:00:00 CST 1955Mon Oct 1 00:00:00 CST 1956Tue Oct 1 00:00:00 CST 1957Wed Oct 1 00:00:00 CST 1958Thu Oct 1 00:00:00 CST 1959Sat Oct 1 00:00:00 CST 1960Sun Oct 1 00:00:00 CST 1961Mon Oct 1 00:00:00 CST 1962Tue Oct 1 00:00:00 CST 1963Thu Oct 1 00:00:00 CST 1964Fri Oct 1 00:00:00 CST 1965Sat Oct 1 00:00:00 CST 1966Sun Oct 1 00:00:00 CST 1967Tue Oct 1 00:00:00 CST 1968Wed Oct 1 00:00:00 CST 1969Thu Oct 1 00:00:00 CST 1970Fri Oct 1 00:00:00 CST 1971Sun Oct 1 00:00:00 CST 1972Mon Oct 1 00:00:00 CST 1973Tue Oct 1 00:00:00 CST 1974Wed Oct 1 00:00:00 CST 1975Fri Oct 1 00:00:00 CST 1976Sat Oct 1 00:00:00 CST 1977Sun Oct 1 00:00:00 CST 1978Mon Oct 1 00:00:00 CST 1979Wed Oct 1 00:00:00 CST 1980Thu Oct 1 00:00:00 CST 1981Fri Oct 1 00:00:00 CST 1982Sat Oct 1 00:00:00 CST 1983Mon Oct 1 00:00:00 CST 1984Tue Oct 1 00:00:00 CST 1985Wed Oct 1 00:00:00 CST 1986Thu Oct 1 00:00:00 CST 1987Sat Oct 1 00:00:00 CST 1988Sun Oct 1 00:00:00 CST 1989Mon Oct 1 00:00:00 CST 1990Tue Oct 1 00:00:00 CST 1991Thu Oct 1 00:00:00 CST 1992Fri Oct 1 00:00:00 CST 1993Sat Oct 1 00:00:00 CST 1994Sun Oct 1 00:00:00 CST 1995Tue Oct 1 00:00:00 CST 1996Wed Oct 1 00:00:00 CST 1997Thu Oct 1 00:00:00 CST 1998Fri Oct 1 00:00:00 CST 1999Sun Oct 1 00:00:00 CST 2000Mon Oct 1 00:00:00 CST 2001Tue Oct 1 00:00:00 CST 2002Wed Oct 1 00:00:00 CST 2003Fri Oct 1 00:00:00 CST 2004Sat Oct 1 00:00:00 CST 2005Sun Oct 1 00:00:00 CST 2006Mon Oct 1 00:00:00 CST 2007Wed Oct 1 00:00:00 CST 2008Thu Oct 1 00:00:00 CST 2009Fri Oct 1 00:00:00 CST 2010Sat Oct 1 00:00:00 CST 2011Mon Oct 1 00:00:00 CST 2012使用管道,将输出重定向到文本文件 cal
./Untitled1 > cal现在处理cal就好了
#include <bits/stdc++.h>using namespace std;int main(){ freopen("cal", "r", stdin); string s; int ans = 0; while (cin >> s) ans += (s == "Sun"); cout << ans << endl;}答案 9
这种搞法Windwos肯定行不通的,到时候再议 : )
新闻热点
疑难解答