|
|
вернуться в форумWhat's Wrong with my answer?WA test#10..It works absolutely perfectly in my computer & all conditions are fulfilled using namespace std; #include<iostream> #include<string> #include<sstream> #include<ctype.h> void factorial(unsigned long n,unsigned long k); int main() { unsigned long counter=0; string s; unsigned long n; while(getline(cin,s)) { counter=0; string::size_type position,position2; position=s.find(' '); string num; for(int i=0;i<position;i++) { if(isdigit(s[i])) num+=s[i]; } stringstream ss(num); ss>>n; position2=s.find('!'); if(position2==position+1) { for(int i=position+1;i<s.size();i++) if(s[i]=='!') counter++; factorial(n,counter); } } } void factorial(unsigned long n,unsigned long k) { unsigned long res=1; int mod=n%k; unsigned long mul=n; if(mod!=0) { while(mul>1) { res*=mul; mul=mul-k; } cout<<res<<endl; } else { while(mul>=k) { res*=mul; mul=mul-k; } cout<<res<<endl; } } Edited by author 05.04.2018 15:46 Edited by author 05.04.2018 15:47 |
|
|