prob
void calc_probability(int num)
{
int i = , j = , k = ;
#define SIZE_NUM 8
int *array_num = NULL;
int *remember_num = NULL;
char (**array_detail)[SIZE_NUM] = NULL; //数组指针
int len_array = ;
int count_num = ;
int count = ; len_array = * num - ;
array_num = (int*)calloc(len_array, sizeof(int));
array_detail = (char (**)[SIZE_NUM])calloc(len_array, sizeof(char(*))); //这里注意是sizeof(char(*)不是sizeof(char(*)[SIZE_NUM])
remember_num = (int*)calloc(len_array, sizeof(int)); for(i = ; i < len_array; i++)
{
array_num[i] = i + ;
array_detail[i] = (char(*)[SIZE_NUM])calloc(count_num + , sizeof(char[SIZE_NUM]));
} for(i = ; i < len_array; i++)
{
count = ; // 计数清零
count_num = ;
for(j = ; j <= num; j++)
{
for(k = ; k <= num; k++)
{
if(j + k == array_num[i])
{
sprintf(array_detail[i] + count_num, "(%d, %d)", j, k);
//printf("%s", array_detail[i] + count_num);
count_num++;
count++;
array_detail[i] = (char(*)[SIZE_NUM])realloc(array_detail[i], (count_num + ) * sizeof(char[SIZE_NUM]));
memset(array_detail[i] + count_num, 0x0, SIZE_NUM);
}
}
}
remember_num[i] = count;
} for(i = ; i < len_array; i ++)
{
printf("数字 %d 的个数是: %d\n", i + , remember_num[i]);
for(j = ; j < remember_num[i]; j++)
{
printf("%s ", array_detail[i] + j);
}
printf("\n");
} //释放内存
free(remember_num);
remember_num = NULL; free(array_num);
array_num = NULL; for(i = ; i < len_array; i++)
{
free(array_detail[i]);
array_detail[i] = NULL;
}
free(array_detail);
array_detail = NULL; return; }
错了好多次,终于改对了。
prob的更多相关文章
- Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1) Checks autowiring prob
Intellij Idea开发工具在@Autowired或者@Resource注入XxxMapper接口时报如下错误: Could not autowire. No beans of 'TbItemM ...
- soj1022. Poor contestant Prob
1022. Poor contestant Prob Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As everyb ...
- NOIP 2011 Day 1 部分题解 (Prob#1 and Prob#2)
Problem 1: 铺地毯 乍一看吓cry,地毯覆盖...好像是2-dims 线段树,刚开头就这么难,再一看,只要求求出一个点,果断水题,模拟即可.(注意从标号大的往小的枚举,只要有一块地毯符合要求 ...
- The `XXXX` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-game-desktop/Pods-game-desktop.release.xcconfig'. This can lead to prob
The `game-desktop [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Po ...
- 【AIM Tech Round 4 (Div. 2) D Prob】
·题目:D. Interactive LowerBound ·英文题,述大意: 有一个长度为n(n<=50000)的单链表,里面的元素是递增的.链表存储在一个数组里面,给出长度n.表 ...
- 1.1.5 PROB Friday the Thirteenth
Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the mont ...
- 1.1.4 PROB Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- 1.1.1 PROB Your Ride Is Here
=== /* ID: luopengting PROG: ride LANG: C++ */ #include <iostream> #include <cstdio> #in ...
- XSY contest1586 proB
题目 现在一圈n个花坛, 每次随机往一个花盆里种花, 一个花盆可以种多颗花, 假如一个花盆两边的花盆都有花, 那么他也将被种上花 问期望种满所有花盆要种几次 首先定义f(i)为放置了i个物品后完全覆盖 ...
随机推荐
- Opencv step by step - 视频进度条
上一个博文只是进行了视频播放,这里加上进度条. 下面是修改好的代码: #include <cv.h> #include <highgui.h> /* * tan@ubuntu: ...
- 从无重复大数组找TOP N元素的最优解说起
有一类面试题,既可以考察工程师算法.也可以兼顾实践应用.甚至创新思维,这些题目便是好的题目,有区分度表现为可以有一般解,也可以有最优解.最近就发现了一个这样的好题目,拿出来晒一晒. 1 题目 原文: ...
- Web fonts
不同类型的文件字体: Embedded OpenType (glyphicons-halflings-regular.eot) Scalable Vector Graphics (glyphicons ...
- Siege——多线程编程最佳实例
在英语中,“Siege”意为围攻.包围.同时Siege也是一款使用纯C语言编写的开源WEB压测工具,适合在GNU/Linux上运行,并且具有较强的可移植性.之所以说它是多线程编程的最佳实例,主要原因是 ...
- QQ提醒的功能
原文出处:http://www.cnblogs.com/xiexingen/archive/2013/04/09/3009921.html http://qzs.qq.com/snsapp/app/b ...
- 08.C# System.Nulable<T>和空引用操作符(四章4.2-4.4)
看了这3小节,发现作者讲得太详细了,把一个都在正常使用的用法说得太神密了,搞得不知是自己不懂作者的苦心,还是作者用意为之,这里给大家都简单讲下吧,太深的真心讲不下去. 1.可空类型的核心部分是Syst ...
- [C#基础]说说委托+=和-=的那些事
写在前面 为什么会突然想说说委托?原因吗,起于一个同事的想法,昨天下班的路上一直在想这个问题,如果给委托注册多个方法,会不会都执行呢?为了一探究性,就弄了个demo研究下. += 大家都知道委托都继承 ...
- DOM(七)使用DOM控制表格
表格的css控制就先不说了,首先分享下表格常用的DOM 表格添加操作的方法常用的为insertRow()和insertCell()方法. row是从零开始计算起的,例如: var oTr = docu ...
- 怎么让alert弹出框的内容可以换行?
在要点击弹出的地方输入这样的代码: alert("文本框中共有字母a的个数为:"+num+"\n"+"他们在字符串的索引为:"+ind) 就 ...
- Excel 计算 tips
1. 对一列数据想看看,distinct的结果 选中数据区域(包含列名),插入pivot table 2. 想检查一个单元格的值在不在某一列中,并返回标志值 =IF (COUNTIF(B:B,A1) ...