练习时长2秒半的蒟蒻24pts求助

P1202 [USACO1.1] 黑色星期五Friday the Thirteenth

```cpp hack: 输入:5 输出:9 9 7 9 9 8 9 ```
by _harvey2019_ @ 2022-10-23 18:46:51


~~你做的事**黑子星期五**罢(恼~~
by _Ginoo_ @ 2022-10-23 19:05:41


@[harvey2019](/user/283541) ~~练习时长太短了,回去修炼~~ ①:二月闰年多一天的判断: `for( i = 0 ; i < 12 ; i++ )` 和 `( i == 2 )`这都哪跟哪啊? `( ( year % 100 || year % 400 == 0 ) && year % 4 == 0 )` 你这闰年判断还能这么搞吗? 逻辑应该这么写: `month=i+1;` `(month==2&&(year%400==0||year%100!=0&&year%4==0))` ②:题目要求计算日期从1900年开始 `for( year = 1900 ; year < 1900 + n ; year++ )` ③:1900年的1月13日是星期六 `改为` ④:输出问题 依次输出周六、日、一、二、三、四、五在 13 日出现的次数。
by Terrible @ 2022-10-23 19:21:39


③:改为`int xq = 5;`
by Terrible @ 2022-10-23 19:22:14


@[Terrible](/user/195942) 感谢您的回复,但是1我改了,2我是1900年开始的啊?3、4、5因为1900.1.13是星期6,所以把吧星期6看作第一个数( 但是,现在是36pts了…… ```cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef float fl; typedef double dou; typedef long double ld; #define register int ri; const ll inf = 1e9; const ll inf_common = 0x3f3f3f3f; const ll inf_larger = 0x7fffffff; const ll inf_ll = 1e18; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const dou eps = 1e-6; inline ll read() { ll ans = 0; ll f = 1; char c = getchar(); while( c < '0' || c > '9' ) { if( c == '-' ) { f = -1; } c = getchar(); } while( c >= '0' && c <= '9' ) { ans = ( ans << 3 ) + ( ans << 1 ) + ( c - 48 ); c = getchar(); } return ans * f; } inline void write( ll x ) { if( x < 0 ) { putchar( '-' ); x = -x; } if( x > 9 ) { write( x / 10 ); } putchar( x % 10 + '0' ); } int dpm[] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 }; int times_day[11] = {0}; int main() { int n = read(); int i = 0; int xq = 0; int year = 0; for( year = 1990 ; year < 1990 + n ; year++ ) { for( i = 0 ; i < 12 ; i++ ) { times_day[xq]++; xq = ( xq + dpm[i] + ( ( i == 1 ) && ( year % 100 || year % 400 == 0 && year % 4 == 0 ) ) ) % 7; } } for( i = 0 ; i < 7 ; i++ ) { write( times_day[i] ); putchar( ' ' ); } return 0; } ```
by _harvey2019_ @ 2022-10-24 16:13:22


@[harvey2019](/user/283541) ```cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read() { ll ans = 0; ll f = 1; char c = getchar(); while( c < '0' || c > '9' ) { if( c == '-' ) { f = -1; } c = getchar(); } while( c >= '0' && c <= '9' ) { ans = ( ans << 3 ) + ( ans << 1 ) + ( c - 48 ); c = getchar(); } return ans * f; } inline void write( ll x ) { if( x < 0 ) { putchar( '-' ); x = -x; } if( x > 9 ) { write( x / 10 ); } putchar( x % 10 + '0' ); } int dpm[] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 }; int times_day[11] = {0}; int main() { int n = read(); int i = 0; int xq = 5; int year = 0; for( year = 1900 ; year < 1900 + n ; year++ ) { for( i = 0 ; i < 12 ; i++ ) { times_day[xq]++; xq = ( xq + dpm[i] + ( ( i == 1 ) && ( year % 400 == 0 || year % 100 && year % 4 == 0 ) ) ) % 7; } } for( i = 5 ; i < 7 ; i++ ) { write( times_day[i] ); putchar( ' ' ); } for( i = 0 ; i < 5 ; i++ ) { write( times_day[i] ); putchar( ' ' ); } return 0; } ```
by Terrible @ 2022-10-24 22:20:22


@[Terrible](/user/195942) 谢谢,我测一下
by _harvey2019_ @ 2022-10-24 22:22:34


@[Terrible](/user/195942) 谢谢!(我也看您交了一次),无以为报给您两个关注吧)
by _harvey2019_ @ 2022-10-24 22:25:44


已过,此帖结。
by _harvey2019_ @ 2022-10-24 22:26:03


|