C语言Lesson5
来源:互联网 发布:淘宝退货信用卡手续费 编辑:程序博客网 时间:2024/06/02 00:46
// 行列交换,
int array[2][3] = {{7, 6, 8},{ 2, 4, 5}};
int array1[3][2] = {0};
for (int i = 0; i < 3; i++) {
for (int j = 0 ; j < 2; j++) {
array1[i][j] = array[j][i];
printf("%d ", array1[i][j]);
}
printf("\n");
}
// 一维模拟二维
// int array[6] = {7, 6, 5, 8, 3, 1};
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < 3; j++) {
// printf("%d ", array[i * 3 + j]);
// }
// printf("\n");
// }
// 打乱排序
// int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
// int count = sizeof(a) / sizeof(a[0]);
// for (int i = count - 1 ; i >= 0 ; i--) {
// int random = arc4random() % (i + 1);
// printf("%d\n", a[random]);
// int temp = 0;
// temp = a[random];
// a[random] = a[i];
// a[i] = temp;
// }
// for (int i = 0; i < count; i++) {
// printf("[%2d] : %d\n", i, a[i]);
// }
// int array[] = {3, 2, 6, 9, 8, 5, 7, 1, 4};
// 冒泡
// int count = sizeof(array) / sizeof(array[0]);
// int flag = 1;
// for (int i = 0 ; i < count - 1; i++) {
// flag = 0;
// for (int j = 0; j < count - i - 1; j++) {
// if (array[j] > array[j + 1]) {
// int temp = 0;
// temp = array[j];
// array[j] = array[j + 1];
// array[j + 1] = temp;
// flag = 1;
// }
// }
// }for (int i = 0; i < count; i++) {
// printf("[%2d] : %d\n", i, array[i]);
// }
// 选择
// int count = sizeof(array) / sizeof(array[0]);
// for (int i = 0; i < count; i++) {
// int mid = i;
// for (int i = mid; i < count; i++) {
// if (array[mid] > array[i]) {
// mid = i;
// }
// }
// int temp = 0;
// temp = array[mid];
// array[mid] = array[i];
// array[i] = temp;
// }for (int i = 0; i < count; i++) {
// printf("[%2d] : %d\n", i, array[i]);
// }
// 插入排序
// int count = sizeof(array) / sizeof(array[0]);
// for (int i = 0; i < count; i++) {
// int j = i;
// int temp = array[j];
// while (j > 0 && temp < array[j - 1]) {
// array[j] = array[j - 1];
// j--;
// }
// array[j] = temp;
// }for (int i = 0; i < count; i++) {
// printf("[%2d] : %d\n", i, array[i]);
// }
// int array[] = {4, 1, 2, 9, 8, 7, 6, 5, 3};
// 折半查找
// int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
// int count = sizeof(array)/ sizeof(array[0]);
// int start = 0, end = count - 1, mid = 0, c = 0;
// scanf("%d", &c );
// while (start <= end) {
// mid = (start + end) / 2;
// if (array[mid] > count) {
// end = mid - 1;
// }else if (array[mid] < c ){
// start = mid + 1;
// }else {
// break;
// }
// }
// if (start <= end) {
// printf("[%2d] : %d\n", mid, array[mid]);
// }else{
// printf("not found\n");
// }
// int n = 5, m = 4;
// int a[5] = {0};
// int count = 0;
// int number = 1;
// int i = 0;
// while (count < 5) {
// if (a[i] == 0) {
// if (number != m) {
// number++;
// i++;
// if (i >= n) {
// i = 0 ;
// }
// }else {
// a[i] = 1;
// number = 1;
// printf("%d\n", i);
// count++;
// i++;
// if (i >= n) {
// i = 0;
// }
// }
// } else {
// i++;
// if (i >= n) {
// i = 0;
// }
// }
// }
// 随机二维数组,最大值,所在位置
// int array[3][4] = {0};
// int count = sizeof(array) / sizeof(array[0]);
// int count1 = sizeof(array[0]) / sizeof(array[0][0]);
// for (int i = 0; i < count; i++) {
// for (int j = 0 ; j < count1; j++) {
// array[i][j] = arc4random() % 100;
// printf("%d\n", array[i][j]);
// }
// printf("\n");
// }
// int maxi = 0, maxj = 0;
// for (int i = 0; i < count; i++) {
// for (int j = 0; j < count1; j++) {
// printf("[%2d] [%2d] : %d\n", i, j, array[i][j]);
// if (array[maxi][maxj] < array[i][j]) {
// maxi = i;
// maxj = j;
// }
// }
// }
// printf("[%2d] [%2d]\n", maxi, maxj);
字符串拼接
// char strings[3][10] = {"iphone","Android","win8"};
// int count =sizeof(strings) / sizeof(strings[0]);
// int count1 = sizeof(strings[0]) / sizeof(strings[0][0]);
// for (int i = 0; i < count; i++) {
// for (int j = 0; j < count1; j++) {
// printf("%c", strings[i][j]);
// }
// printf("\n");
//}
字符串比较
// char names[][20] = {"wei", "jiang", "liu", "she"};
// unsigned long maxlenth = 0;
// int count = sizeof(names) / sizeof(names[0]);
// for (int i = 0; i < count; i++) {
// if (maxlenth < strlen(names[i])) {
// maxlenth = strlen(names[i]);
// }
// }
// printf("maxlenth = %lu\n", maxlenth);
// 三维数组
// int array[2][4][3] = {0};
// for (int i = 0; i < 2; i++) {
// for (int j = 0; j < 4; j++) {
// for (int k = 0; k < 3; k++) {
// array[i][j][k] = arc4random() % 100;
// printf("%2d ", array[i][j][k]);
// }
// printf("\n");
// }
// printf("\n");
// }
// 面试题:字符串去数字
// char string[] = "a12b3c45d78";
// char string1[strlen(string) + 1];
// int i = 0, j = 0;
// while (string[i] != '\0') {
// if (string[i] < '0' || string[i] > '9' ) {
//
// string1[j] = string[i];
// j++;
// }
// i++;
// }
// string1[j] = '\0';
// printf("%s\n", string1);
升级版
// char string[] = "a12b34c56d79";
// int i = 0, j = 0;
// while (string[i] != '\0') {
// if (string[i] < '0' || string[i] > '9') {
// string[j] = string[i];
// j++;
// }
// i++;
// }
// string[j] = '\0';
// printf("%s\n", string);
// 面试题:中间值
// int i = 0, j = 0;
// while (string[i] != '\0') {
// if ('\0' == string[i]) {
// break;
// }
// i++;
// if ('\0' == string[i]) {
// break;
// }
// i++;
// j++;
// }
// printf("%c\n", string[j]);
// 索引
// int array[] = {3, 2, 6, 9, 8, 5, 7, 1, 4};
// int indexs[] = {7, 1, 0, 8, 5, 2, 6, 4, 3};
// for (int i = 0; i < 9; i++) {
// printf("[%2d] : %d\n", indexs[i], array[indexs[i]]);
// }
// 二路归并法
// int a[] = {0, 1, 2, 3, 4, 5};
// int b[] = {6, 7, 8, 9, 10};
// int counta = sizeof(a) / sizeof(a[0]);
// int countb = sizeof(b) / sizeof(b[0]);
// int c[counta + countb];
// int i = 0, j = 0, k = 0;
// while (i < counta && j < countb) {
// if (a[i] < b[j]) {
// c[k] = a[i];
// i++;
// } else {
// c[k] = b[j];
// j++;
// }
// k++;
// }
// while (i < counta) {
// c[k++] = a[i++];
// }
// while (j < countb) {
// c[k++] = b[j++];
// }
// for (int i = 0; i < counta + countb; i++) {
// printf("[%2d] : %d\n", i, c[i]);
// }
// 一百万随机出现重复
// int array[1000000] = {0};
// while (1) {
// int random = arc4random() % (10000000 + 1);
// array[random] = random;
// if (array[random] == 0) {
// } else {
// printf("%d\n", array[random]);
// }
// }
// int index1[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
// int index2[9] = {7, 1, 0, 8, 5, 2, 6, 4, 3};
// for (int i = 0; i < 9; i++) {
// printf("%d\n", array[index1]);
// }
// for (int i = 0; i < 9; i++) {
// printf("%d\n", array[index2]);
// }
//
// 索引数组折半查找
// int array[] = {3, 2, 6, 9, 8, 5, 7, 1, 4};
// int count = sizeof(array) / sizeof(array[0]);
// int index3[count];
// for (int i = 0; i < count ; i++) {
// index3[i] = i;
// printf("%d\n", index3[i]);
// }
- C语言Lesson5
- C语言提高班学习笔记 lesson5 编译
- C语言学习笔记 lesson5 浮点数类型及复习
- C语言提高班学习笔记 lesson5 变量、指针
- lesson5
- Windows程序设计__孙鑫C++Lesson5《文本操作》
- LogicJava---Lesson5
- csdnS2-lesson5
- Lesson5 Recursion
- lesson5~键盘
- lesson5:文本编辑
- lesson5-1
- lesson5-2
- Lesson5 接口
- Lesson5 接口
- Lesson5:文本编程
- 黑马程序员-lesson5
- VC++笔记(Lesson5-Lesson7)
- PHP多种序列化/反序列化的方法 serialize,json_encode等
- Flex与Java编程语言的相似之处
- HDU 3072 Intelligence System
- linux 内核配置
- 速度——人类的一个本性
- C语言Lesson5
- 十大编程字体
- android代码全屏与非全屏
- Shell 命令--文件创建、搜索命令--总结自《Linux Shell 脚本攻略》
- 计算机视觉、机器学习相关领域论文和源代码
- HDU 3594 Cactus
- flex用getFullYear()自动获取当年年份
- 两个主要问题将决定微信支付成败
- 做事分主次