题目
{% raw %}
{% endraw %}
小明出生于1937年7月7日,问对于给定的日期,小明几周岁了,不足一周年的部分可以忽略。
注意:1938年7月6日,小明0周岁,1938年7月7日小明1周岁,同理1939年7月6日,小明1周岁,1939年7月7日,小明2周岁。
{% raw %}
{% endraw %}
一个整数t(1<=t<=100),表示数据组数
对于每组测试数据,三个整数,逗号隔开,分别表示给定日期的年、月、日。给定的日期保证合法, 而且一定是小明出生后的日期,且小明的岁数保证在100以内。
{% raw %}
{% endraw %}
对于每一组数据,输出一个整数,表示小明的周岁数。
{% raw %}
{% endraw %}
2
1938 7 6
1938 7 7
{% raw %}
{% endraw %}
0
1
{% raw %}
题解
先计算去年到出生年份之间的年数,这一部分是无论有没有过今年生日都应该算上的
然后再判断今年有没有过生日,先比较月份,月份一样看日期
代码
```cpp 今年多少岁 https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
/*/
#define debug
#include
//*/
#include
#include
#include
using namespace std;
int main(){
#ifdef debug
freopen("in.txt", "r", stdin);
int START = clock();
#endif
cin.tie(0);
cin.sync_with_stdio(false);
int T;
cin >> T;
while(T--){
int y,m,d;
cin >> y >> m >> d;
int ans = y - 1937 - 1;
if(m > 7 || (m == 7 && d >= 7))
ans++;
cout << ans << endl;
}
#ifdef debug
printf("Time:%.3fs.\n", double(clock() - START) / CLOCKS_PER_SEC);
#endif
return 0;
}
</div>