标签:style blog class code c tar
FizzBuzzWhizz
你是一名体育老师,在某次课距离下课还有五分钟时,你决定搞一个游戏。此时有100名学生在上课。游戏的规则是:
1 #include<iostream> 2 #include<cstring> 3 #include<string> 4 5 using namespace std; 6 7 void FizzBuzzWhizz(int a, int b ,int c,int range); 8 9 void FizzBuzzWhizz(int a, int b ,int c,int range) 10 { 11 char s[10]; 12 sprintf_s(s,"%d",a); 13 for(int i = 1; i <= range; i++) 14 { 15 string strout; 16 char temp[10]; 17 sprintf_s(temp,"%d",i); 18 string str(temp); 19 if(str.find(s)!= string::npos) 20 { 21 strout += "Fizz"; 22 } 23 else 24 { 25 if(i%a==0) 26 { 27 strout += "Fizz"; 28 } 29 if(i%b==0) 30 { 31 strout += "Buzz"; 32 } 33 if(i%c==0) 34 { 35 strout += "Whizz"; 36 } 37 if (strout.empty()) 38 { 39 strout = str; 40 } 41 } 42 cout << temp << " " << strout <<endl; 43 } 44 } 45 46 int main(void) 47 { 48 int num1,num2,num3,range; 49 while(1) 50 { 51 cout << "请输入3个特殊数和总人数:"; 52 cin >> num1 >> num2 >> num3 >> range; 53 if(num1<0 || num2<0 || num3<0 || range<0 || num1==num2 || num1==num3 || num2==num3) 54 { 55 cout << "请输入正确的特殊数和总人数" << endl; 56 } 57 else 58 { 59 FizzBuzzWhizz(num1,num2,num3,range); 60 } 61 } 62 }
1 def FizzBuzzWhizz(p_a,p_b,p_c): 2 for x in xrange(1,100): 3 print x,"Fizz"[0 if str(x).find(str(p_a))>-1 else 4:] or "Fizz"[x%p_a*4:] + "Buzz"[x%p_b*4:] + "Whizz"[x%p_c*5:] or x;
标签:style blog class code c tar
原文地址:http://www.cnblogs.com/cxyfreedom/p/3735548.html