C语言_猜测序列和元的生成
猜测序列
#include <stdio.h>
#define maxn 1010
int main(void)
{
int n, a[maxn], b[maxn];
int kase = 0;
int A = 0, B = 0;
while (scanf("%d", &n) == 1 && n){
printf(“Game %d:\n”, ++kase);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for(; ; ) {
for (int i = 0; i < n; i++){
scanf("%d", &b[i]);
if (a[i] == b[i])
A++;
}
if (b[0] == 0)
break;
for (int d = 1; d <= 9; d++){
int c1 = 0, c2 = 0;
for (int i = 0; i < n; i++){
if (a[i] == d) c1++;
if (b[i] == d) c2++;
}
if (c1 < c2) B += c1;
else B += c2;
}
}
printf(" (%d, %d)\n", A, (B - A));
}
return 0;
}
#include <stdio.h>
#include <string.h>
#define maxn 100005
int ans[maxn];
int main(void)
{
int T, n;
memset (ans, 0, sizeof (ans));
for (int m = 1; m < maxn; m++){
int x = m, y = m;
while (x > 0) {y += x % 10; x /= 10;}//核心语句
if (ans[y] == 0 || m < ans[y]) ans[y] = m;//将得出的元填入此位置
}
//查表
scanf("%d", &T);
while(T–){
scanf("%d", &n);
printf("%d\n", ans
);
}
//查表
return 0;
}
- C语言实现分布式自增有序的唯一ID生成算法-snowflake算法
- C语言中的序列点和副作用
- 生成最长递增子序列
- 利用C语言来求最大连续子序列乘积的方法
- [源码和文档分享]基于java的C语言试题生成与考试系统
- C语言 rand 生成随机数
- Nhibernate连接oracle数据库,主键ID用序列生成时连接数据库IO次数分析
- BZOJ 2958: 序列染色 && BZOJ 3193: [JLOI2013]地形生成 —— 肆虐的DP
- 编程珠玑: 13章 搜索 13.1生成[0 ,maxval]范围内m各随机整数的有序序列 -------解题总结
- Random指定生成的随机数序列
- 邻接表生成模型头文件C语言
- 【C语言训练】列出最简真分数序列*
- 先序遍历创建二叉树,对二叉树统计叶子节点个数和统计深度(创建二叉树时#代表空树,序列不能有误)c语言
- C语言实现BMP图片生成
- 2015年阿里在线笔试题:求两个字符串的最大公共子序列长度的C语言解法
- cJson的用法(一) -C语言解析/生成 json数据
- c语言如何生成随机数
- C语言的一个简单算法: 26个字母随机步生成
- Excel工作常用(一)-生成序列与删除空行
- 【转】关于C语言生成不重复的随机数