NC212617. EatGrapes
描述
输入描述
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:
The first line contains an integer N (1 ≤ N ≤ ), indicating the number of nodes.
The second line contains N integers, , ,……, (0 ≤ ≤ ), indicating the number of grapes connected to the i-th node.
输出描述
For each test case, each line contains a string, indicating the sentence which SYH said.
示例1
输入:
2 5 2 1 0 0 1 5 1 1 0 1 0
输出:
these are sweet grapes these are sour grapes
说明:
C(clang11) 解法, 执行用时: 118ms, 内存消耗: 4892K, 提交时间: 2021-01-15 13:36:54
#include<stdio.h> #include<string.h> #define maxn 102020 int a[maxn]; int main(){ int n,m; int t; int sum; scanf("%d",&t); while(t--){ sum=1; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } a[n]++; for(int i=n;i>=1;i--){ if(a[i]>1)break; else if(i!=1)sum=1-sum; } if(sum!=0)printf("these are sweet grapes\n"); else printf("these are sour grapes\n"); } return 0; }
C++14(g++5.4) 解法, 执行用时: 65ms, 内存消耗: 372K, 提交时间: 2020-09-27 20:50:03
#include<stdio.h> int main(){ int T; scanf("%d", &T); while(T--){ int flag = 0, n , x; scanf("%d",&n); for(int i = 1; i <= n; i++){ scanf("%d", &x); if(x == 0) flag = 1 - flag; else flag = 1; } if(flag) printf("these are sweet grapes\n"); else printf("these are sour grapes\n"); } return 0; }
C++11(clang++ 3.9) 解法, 执行用时: 146ms, 内存消耗: 388K, 提交时间: 2020-09-26 16:15:10
#include<bits/stdc++.h> using namespace std; int ans,T,n,x; int main(){ cin>>T; while(T--){ cin>>n>>x; if(x==0)ans=0; else ans=1; for(int i=1;i<n;i++){ cin>>x; if(x>0)ans=1; else ans=1-ans; } if(ans) cout<<"these are sweet grapes\n"; else cout<<"these are sour grapes\n"; } return 0; }