coding----1wcods----坚持第7天----1152行
2013-12-30 01:31
323 查看
#include <stdio.h> int main() { int x, y, z; x = 2; x *= (y=z=5); printf("%d\n",x); z = 3; x == (y=z); printf("%d\n",x); x = (y==z); printf("%d\n",x); x = y&z; printf("%d\n",x); x = y&&z; printf("%d\n",x); x = y|z; printf("%d\n",x); x = y||z; printf("%d\n",x); return 0; } #include <stdio.h> /* 统计对应二进制数中1的个数*/ int function(int x) { int count = 0; while (x) { count ++; x = x &(x -1); } return count; } int main() { printf ("%d\n",function(7)); return 0; } #include <stdio.h> int main() { int a, x; /* 先检查a<=1是否满足条件,满足再检查 !x++,否则直接退出*/ for (a = 0,x =0; a <=1 && !x++;a++) { a ++; } printf ("a=%d,x=%d\n",a,x); /* 先检查a<=1是否满足条件,满足再检查 !x++,否则直接退出*/ for (a = 0,x =0; a <=1 && !x++;) { a ++; } printf ("a=%d,x=%d\n",a,x); return 0; } #include <stdio.h> int main() { int b = 3; int arr[] = {6,7,8,9,10}; int *ptr = arr; *(ptr++) += 123; printf ("%d\n",*(ptr -1)); /* printf执行的时候是从右向左压栈, * 也就是先执行右边参数的计算,再计算左边的 */ //printf ("%d,%d\n",*ptr,*(ptr++)); printf ("%d,%d\n",*ptr,*(++ptr)); return 0; } #include <stdio.h> #include <stdbool.h> /* 顶点类型*/ typedef char vertex_type; /* 边界类型,存放权重或顶点关系*/ typedef int edge_type; #define MAXVERTEX (100) /* 区分权重,代表无穷大*/ #define INFINITY (65535) typedef struct { /* 顶点表*/ vertex_type vertex[MAXVERTEX]; /* 邻接表*/ edge_type edge[MAXVERTEX][MAXVERTEX]; /* 当前图的边界,顶点数目*/ int cur_num_edge, cur_num_vertex; }graph_type; void flush () { char ch; while ((ch = getchar()) != '\n' && ch != EOF); } /* 创建无向网图的,邻接矩阵*/ void create_undirected_graph (graph_type *graph) { printf ("enter the number of vertexs and edges\nfor example 10 10\n"); scanf ("%d %d",&graph->cur_num_vertex,&graph->cur_num_edge); flush(); for (int i =0;i < graph->cur_num_vertex;i ++) for (int j = 0; j < graph->cur_num_vertex; j++) graph->edge[i][j] = INFINITY; printf ("enter the vertexs\n"); for (int i = 0;i < graph->cur_num_vertex; i++) { scanf ("%c",&graph->vertex[i]); flush(); } int i, j, weight; for (int k =0; k <graph->cur_num_edge; k++) { printf ("enter the i,j of (vi,vj) and weight\n"); scanf ("%d %d %d",&i,&j,&weight); flush(); graph->edge[i][j] = weight; graph->edge[j][i] = graph->edge[i][j]; } } /* 访问标志数组*/ int visited[MAXVERTEX]; /* 深度优先遍历DFS*/ void DFS(graph_type *g,int i) { visited[i] = true; /* 打印访问到的节点,也可以进行其他操作*/ printf ("%c",g->vertex[i]); for (int j =0;j < g->cur_num_vertex;j++){ if (g->edge[i][j] ==1 && !visited[j]) DFS(g,j); } } void DFS_traverse (graph_type *g) { for (int i =0;i < g->cur_num_vertex;i++) { visited[i] = false; } for (int i =0;i < g->cur_num_vertex;i ++) { if (!visited[i]) DFS(g,i); } } int main () { graph_type graph_tst; create_undirected_graph (&graph_tst); DFS_traverse (&graph_tst); printf("\n"); return 0; }
相关文章推荐
- Comparing Xamarin and Delphi XE5 to Xcode for Cross Platform Mobile App Development
- [leetcode]Jump Game
- 浅析Python中的列表解析和生成表达式
- Python如何备份目录及目录下的全部内容
- Python入门之你必须了解的实用技巧
- Python高手是如何练成的
- 卡尔曼滤波 -- 从推导到应用(一)
- Python入门之你必须了解的语法与类型
- 卡尔曼滤波 -- 从推导到应用(一)
- Linux tar打包命令
- 《大话设计模式》Python版代码实现
- #pragma once 与 #ifndef 解析
- Python序列的切片操作与技巧
- WebView Attack In Android : 解析第三方账号登录平台所存在的安全隐患
- Python的Lambda函数与排序
- 加速你的Python代码
- delphi中IDispath接口的实现类
- 动态捕获Python异常
- 搭建高可用mongodb集群(二)—— 副本集
- 一些最基本的开发设计原则方法(整理)