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个物品后完全覆盖 ...
随机推荐
- Spring MVC实现文件下载
下载文件① 下载文件需要将byte数组还原成文件. 首先使用mybatis将数据库中的byte数组查出来,指定文件名(包括格式).然后使用OutputStream将文件输入 @RequestMapp ...
- 路由器 NorFlash与NandFlash区别
在淘宝上买修改openwrt的路由器,基本上都是改的16MB flash,那么为什么不改到1GB呢? 现在U盘的价格也很便宜啊. 于是我调查了一下,发现flash分为两种,NorFlash与NandF ...
- 5.HBase In Action 第一章-HBase简介(1.1.3 HBase的兴起)
Pretend that you're working on an open source project for searching the web by crawling websites and ...
- IT男的”幸福”生活"续2
“呵呵,来,下步如何呢?" …. 下步行动 (主动出击,表明态度) 分析如下: 经过爬山这么一活动,大大增强了认知感,让MM对我的排斥感减低了相当多,在MM心里有我的印象. 而我目的虽然明显,但 ...
- 自定义带图片和文字的ImageTextButton
今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...
- Bootstrap系列 -- 31.嵌套分组
我们常把下拉菜单和普通的按钮组排列在一起,实现类似于导航菜单的效果.使用的时候,只需要把当初制作下拉菜单的“dropdown”的容器换成“btn-group”,并且和普通的按钮放在同一级 <di ...
- express 笔记 app.helpers 和 app.locals
app.helpers 和app.dynamicHelpers 是express2.X使用的 分别为静态/动态 视图助手通过其注册函数, 例如 app.helpers({ <span style ...
- groovyConsole — the Groovy Swing console
1. Groovy : Groovy Console The Groovy Swing Console allows a user to enter and run Groovy scripts. T ...
- 解决 pathForResource 返回 nil的问题
点击(此处)折叠或打开 NSString* path = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@&quo ...
- Chrome的Crash Report服务
<本文转自:http://www.cppblog.com/woaidongmao/archive/2009/10/22/99211.aspx> 本文翻译自debugInfo网站上一篇文章g ...