[C] datalab_handout: Bit operation

2022-3-17 写技术

/* * CS:APP Data Lab * * <Please put your name and userid here> * * bits.c - Source file with your solutions to the Lab. * This is the file you will hand in to your instructor. * * WARNING: Do not include the <stdio.h> header; it confuses the dlc * compiler...

阅读全文>>

标签: C

评论(0) 浏览(635)

数组越界fopen时程序奔溃

2020-3-27 写技术

历史上最奇葩的bug,一运行到fopen语句程序就挂了,按理说就算文件打开失败也就是反回个空指针,为什么这里会直接导致程序奔溃呢,一点一点地把代码删减后定位到数组越界。

阅读全文>>

标签: C

评论(0) 浏览(1265)

[embeded] A sample of searial port communication

2019-7-10 写技术

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <termios.h> void main() { struct termios opt; int tty; int len; int i; unsigned...

阅读全文>>

标签: embedded C linux

评论(0) 浏览(1132)

[C] About phrash on function

2019-4-29 写技术

#include <stdio.h> #include <stdlib.h> typedef struct _ss{ int a; int b; }ss; void fun( ss &s){ s.a = 2; s.b = 3; printf("fun:%d %d\n", s.a, s.b); } void fun2(ss *s){ s->a=55; printf("fun2:%d %d\n", s->a, s->b); } void fun3(ss *s){ fun(*s); ...

阅读全文>>

标签: C

评论(0) 浏览(1101)

[OJ]1015: 机器人训练

2019-2-25 写技术

Description Dr. Shelden最近制造了一种新机器人,现在他要开始给他的机器人做一些简单训练啦。 Shelden在实验室的地面上铺了一些箭头,这些箭头可以看成是二维平面上的一些有向线段,而且都是水平线段或垂直线段,将这些线段从1开始编号,机器人一开始在第1条线段的起点处。现在shelden要写一个程序让他的机器人能够规划一条最短的路径按编号顺序从小到大通过所有的有向线段(只有从线段的起点走到终点才算通过)。机器人每次都只能做90°转弯,而且由于每次转弯都将耗费很大能量,所以shelden希望所求路径的转弯总次数最少。比如在下面这个例子中,实验...

阅读全文>>

标签: C

评论(0) 浏览(1154)

[OJ]1014:西湖三人行

2019-2-19 写技术

Description 去年10月份,FightOn队伍的三个人YZW、HKX、WX在参加完杭州赛区后想到杭州最有名的西湖去玩。他们所能选择的交通方式只有三种: 走路,速度为1m/s,每人每千米花费1元钱(因为他们会消耗体力,需要买水、食物等)。 搭公交,速度为4m/s,每人2元,每条公交路线都按照一定的方向。 打的,速度为8m/s,起步价3千米内10元,以后每千米2元,每个站点都有的士。 当然杭州的交通秩序不像长沙,所以如果想改变交通方式只能在每个站点改换。三个人现在囊中羞...

阅读全文>>

标签: C

评论(0) 浏览(1241)

[OJ]1013: 狐狸与小狗

2019-1-15 写技术

Description Upwinder最近喜欢上了一款古老的起源于Scandinavia(斯堪迪纳维亚半岛)的小游戏。具体的游戏规则如下: 1. 棋盘设定 棋盘的大小为8行8列,有两个玩家:狐狸和小狗。初始的时候有4只小狗被放置在棋盘最上边一行的4个黑色格子里;而1只狐狸被放在最下边一行的某个黑色格子里。以棋盘左上角为原点,向下为行的正方向,向右为列的正方向,从1开始给每一个格子编号. 2. 移动规则 (1) 两个玩家轮流下棋。 (2) 狐狸每轮可以斜着向上或斜着向下移动至相邻的一个空...

阅读全文>>

标签: C

评论(0) 浏览(1326)

[OJ]1012:Prestige

2019-1-14 写技术

Description Are you watching closely? Every great magic trick consists of three acts. The first act is called The Pledge, the magician shows you something ordinary, but of course, it probably isn't. The second act is called The Turn. The magician makes his ordinary something ...

阅读全文>>

标签: C

评论(0) 浏览(1187)

[OJ]1011:Counting Pixels

2019-1-13 写技术

Description Did you know that if you draw a circle that fills the screen on your 1080p high definition display, almost a million pixels are lit? That's a lot of pixels! But do you know exactly how many pixels are lit? Let's find out! Assume that our display is set on a Cartes...

阅读全文>>

标签: C

评论(0) 浏览(1114)

[OJ]1010:Water Drinking

2019-1-13 写技术

Description The Happy Desert is full of sands. There is only a kind of animal called camel living on the Happy Desert. Cause they live here, they need water here. Fortunately, they find a pond which is full of water in the east corner of the desert. Though small, but enough. However...

阅读全文>>

标签: C

评论(0) 浏览(1191)

Powered by anycle 湘ICP备15001973号-1