NC214624. Counting0and1instring
描述
输入描述
The first line contains one integer T (1 ≤ T ≤ 50), the number of test cases.
For each test case, there is only one line containing an integer n (1 ≤ n ≤ 50), which represents the day.
输出描述
For each case, your program will output two integers, representing the number of 0 and the number of 1 in the string after n days.
示例1
输入:
3 1 2 4
输出:
1 1 1 2 3 5
C++(clang++11) 解法, 执行用时: 3ms, 内存消耗: 396K, 提交时间: 2021-01-25 13:41:17
#include "iostream" using namespace std; int main() { long long x,y,t; int n,T; cin>>T; while(T--) { x=1; y=1; cin>>n; while(--n) { t=y; y+=x; x=t; } cout<<x<<' '<<y<<endl; } return 0; }
C(clang11) 解法, 执行用时: 1ms, 内存消耗: 232K, 提交时间: 2020-12-27 12:35:05
#include <stdio.h> int main() { int T; scanf("%d",&T); while(T--) { long long a=1,b=1,c,t; scanf("%lld",&c); c=c-1; while(c--) { t=a; a=b; b=a+t; } printf("%lld %lld\n",a,b); } return 0; }
Python3(3.9) 解法, 执行用时: 14ms, 内存消耗: 2940K, 提交时间: 2020-12-27 12:50:36
n = int(input()) for i in range(n): m = int(input()) a = 0 b = 1 for i in range(m): a, b = b, a + b print(a, b)