412. Fizz Buzz
来源:互联网 发布:正版mac ps软件多少钱 编辑:程序博客网 时间:2024/05/16 00:11
/*Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.Example:n = 15,Return:[ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"]*//** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). *///本体题意就是说每次遇到三,都输出Fizz,每次遇到5,都输出Buzz。每次遇到3与5的倍数,输出FizzBuzz。//11% 6mschar** fizzBuzz(int n, int* returnSize) { *returnSize = n;//返回数组的行数 int i; char** str; char buf[11]; str = (char**)malloc(sizeof(char*)*n); for( i=0; i <n; i++) { if((i+1)%3==0 && (i+1)%5==0 && i) sprintf(buf,"%s","FizzBuzz");//把第三个参数的值复制到第一个参数中 else if((i+1)%3==0) sprintf(buf,"%s","Fizz"); else if((i+1)%5==0) sprintf(buf,"%s","Buzz"); else sprintf(buf,"%d",i+1); str[i] = malloc(sizeof(buf)); memcpy(str[i],buf,strlen(buf)+1);//把第二个内存中的值赋值给第一个参数,赋值范围为第三个参数 memset(buf,"",11); } return str;}
阅读全文
0 0
- 412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- 412. Fizz Buzz
- 412. Fizz Buzz
- [LeetCode]--412. Fizz Buzz
- 412. Fizz Buzz
- LeetCode-412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- 412. Fizz Buzz
- 412. Fizz Buzz
- 【leetcode】412. Fizz Buzz
- LeetCode 412. Fizz Buzz
- 412. Fizz Buzz
- 412. Fizz Buzz
- leetcode 412. Fizz Buzz
- leetcode 412. Fizz Buzz
- Leetcode 412.Fizz Buzz
- leetcode-412. Fizz Buzz
- 排序算法
- 367. Valid Perfect Square
- 383. Ransom Note
- 387.First Unique Character in a String
- 389.Find the Difference
- 412. Fizz Buzz
- spring EnableScheduling标签使用详解
- 巡视整改不能走过场,更不能搞“一风吹”
- Spring04---Annotation注入
- Linux简介
- 济南情况谷歌来看看!
- java 精度的要求
- PHP的password_hash()使用实例
- Spark1.4.0-SparkSQL与Hive整合-支持窗口分析函数