This summer, ZXyang became so tired when doing the problems of Multi-University contests. So he decided to attend the Unified National Graduate Entrance Examination. This day, he sees a problem of series.
Let S(x) be a function with x as the independent variable. S(x) can be represented by the formula as follow.
fi(x) is a function with x as the independent variable. Furthermore. fi(x) belongs to the function set F.
C is a constant integer ranging from 0 to 10^9.
ZXyang wonders if S(x) is convergent. S(x) is convergent if and only if limx→∞S(x)=c, where c is a constant.
Input
The first line of input contains a single integer t (1≤t≤104) — the number of test cases.
The first and the only line of each test case contains a single string s (1≤|s|≤100), indicating the formula of f(x). Fraction is presented as a/b. Cx is presented as C^x. It’s guaranteed that the constant C won’t be left out when C=1. f(x) consists of functions from F connected with +.
Output
For each test case, print YES in one line if S(x) is a convergent sequence, or print NO in one line if not.
Sample Input
2
1sinx+0cosx+3x+6/sinx
0
Sample Output
NO
YES
题意
判断所给函数是否收敛
思路
题中所给的所有函数均为发散。所以只需要检查是否所有的构成函数的系数均为 0 即可
代码
#include<bits/stdc++.h>
using namespace std;
char a[1100],b[1100];
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>a;
int l=strlen(a);
int c,f,k=0;
int ans1=0,ans2=0,ans3=0,ans4=0,ans5=0,ans6=0,ans7=0,ans8=0;
for(int i=0; i<l; i++)
{
if(a[i]!='+')
{
b[k++]=a[i];
if(a[i+1]=='+'||a[i+1]=='\0')
{
b[k]='\0';
c=0;
f=0;
for(int j=0; j<k; j++)
{
if(b[j]>='0'&&b[j]<='9')
{
c=c*10+b[j]-'0';
}
else
{
f=1;
if(b[j]=='/')
{
if(b[j+1]=='x')
ans1+=c;
else if(b[j+1]=='s')
ans2+=c;
else if(b[j+1]=='c')
ans3+=c;
}
else if(b[j]=='x')
ans4+=c;
else if(b[j]=='s')
ans5+=c;
else if(b[j]=='c')
ans6+=c;
else if(b[j]=='^')
ans7+=c;
break;
}
}
if(f==0)
ans8+=c;
k=0;
c=0;
}
}
}
if(!ans1&&!ans2&&!ans3&&!ans4&&!ans5&&!ans6&&!ans7&&!ans8)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}