0%

1. 创建链表的结构体

1
2
3
4
5
6
7
8
9
#include<stdio.h>
#include<malloc.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}linklist;
linklist *p,*head;
阅读全文 »

1. POJ1028

题目

  • Description
    Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this.
    The following commands need to be supported:
    BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.
    FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.
    VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
    QUIT: Quit the browser.
    Assume that the browser initially loads the web page at the URL http://www.acm.org/
阅读全文 »

代码样例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
static int count = 0;
void recur(int i, int n)
{
count++;
printf("B>");
for(i; i <= n; i++)
{
printf("I>");
recur(i + 1, n);
printf("R>");
}
}
int main()
{
int n=1;
recur(0, n);
printf(" COUNT= %d\n", count);
return 0;
}
阅读全文 »

1. 创建线性表的结构体

1
2
3
4
5
6
7
8
9
10
11
#include<stdio.h>
#define maxsize 1024 //线性表的最大长度
typedef int datatype;
//typedef 为C语言的关键字,作用是为一种数据类型定义一个新的名字,
//这种数据类型包括内部数据类型和自定义数据类型
//1. 创建结构体
typedef struct
{
datatype data[maxsize];
int last;
}sequenlist;//结构体名
阅读全文 »

1. 项目一

问题

  • 描述
    判断一个由a-z这26个字符组成的字符串中哪个字符出现的次数最多
  • 输入
    第1行是测试数据的组数n,每组测试数据占1行,是一个由a-z这26个字符组成的字符串
    每组测试数据之间有一个空行,每行数据不超过1000个字符且非空
  • 输出
    n行,每行输出对应一个输入。一行输出包括出现次数最多的字符和该字符出现的次数,中间是一个空格。
    如果有多个字符出现的次数相同且最多,那么输出ascii码最小的那一个字符
  • 样例输入
    2
    abbccc
    adfadffasdf
  • 样例输出
    c 3
    f 4
阅读全文 »

1. strcmp函数

strcmp函数是string compare(字符串比较)的缩写,用于比较两个字符串并根据比较结果返回整数。基本形式为strcmp(str1,str2),若str1=str2,则返回零;若
str1<str2,则返回负数;若str1>str2,则返回正数。

2. strlen函数

strlen所作的是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域)开始扫描,直到碰到第一个字符串结束符’\0’为止,然后返回计数器值(长度不包含’\0’)。

阅读全文 »

1. 进程和线程的解释说明

  • 进程就是操作系统中执行的一个程序,操作系统以进程为单位分配存储空间,每个进程都有自己的地址空间、数据栈以及其他用于跟踪进程执行的辅助数据,操作系统管理所有进程的执行,为它们合理的分配资源。

  • 一个进程还可以拥有多个并发的执行线索,简单的说就是拥有多个可以获得CPU调度的执行单元,这就是所谓的线程。由于线程在同一个进程下,它们可以共享相同的上下文,因此相对于进程而言,线程间的信息共享和通信更加容易。

  • 当然多线程也并不是没有坏处,站在其他进程的角度,多线程的程序对其他程序并不友好,因为它占用了更多的CPU执行时间,导致其他程序无法获得足够的CPU执行时间;另一方面,站在开发者的角度,编写和调试多线程的程序都对开发者有较高的要求,对于初学者来说更加困难。

阅读全文 »

1. poj.org的1003题

题目

  • Description
    How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We’re assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + … + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
    阅读全文 »