#include <iostream>
#include <string>
using namespace std;
int main(){
int t,cs=1;
cin>>t;
while(t--){
cout<<"Case "<<cs++<<": ";
string a,b;
char c;
cin>>c>>c;
while(c!='+'){
a.push_back(c);
cin>>c;
}
cin>>c;
while(c!=')'){
b.push_back(c);
cin>>c;
}
cin>>c;
int n;
cin>>n;
if(n==1){
cout<<a<<'+'<<b<<endl;
continue;
}
int pa=n,pb=0,r=0;
long long cof=1;
while(r<=n){
if(cof>1)
cout<<cof<<'*';
if(pa>1)
cout<<a<<'^'<<pa;
else if(pa==1)
cout<<a;
if(pb&&pa)
cout<<'*';
if(pb>1)
cout<<b<<'^'<<pb;
else if(pb==1)
cout<<b;
if(r<n)
cout<<'+';
r++;
cof*=n-r+1;
cof/=r;
pa--,pb++;
}
cout<<endl;
}
}
#include <string>
using namespace std;
int main(){
int t,cs=1;
cin>>t;
while(t--){
cout<<"Case "<<cs++<<": ";
string a,b;
char c;
cin>>c>>c;
while(c!='+'){
a.push_back(c);
cin>>c;
}
cin>>c;
while(c!=')'){
b.push_back(c);
cin>>c;
}
cin>>c;
int n;
cin>>n;
if(n==1){
cout<<a<<'+'<<b<<endl;
continue;
}
int pa=n,pb=0,r=0;
long long cof=1;
while(r<=n){
if(cof>1)
cout<<cof<<'*';
if(pa>1)
cout<<a<<'^'<<pa;
else if(pa==1)
cout<<a;
if(pb&&pa)
cout<<'*';
if(pb>1)
cout<<b<<'^'<<pb;
else if(pb==1)
cout<<b;
if(r<n)
cout<<'+';
r++;
cof*=n-r+1;
cof/=r;
pa--,pb++;
}
cout<<endl;
}
}
Comments
Post a Comment