Weekly Summary <4>

Source: Internet
Author: User

After a week of study, we have a new knowledge of HTML and C language learning.

Html

Self-study forms, functions, etc.

C language

Havermann encoding

HTML case:

A

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

<title> Untitled Document </title>

<form name= "Form1" method= "Post" action= "" >

<table width= "221" border= "1" cellpadding= "0" cellspacing= "0" >

<tr>

<TD height= "colspan=" 2 "> User login </td>

</tr>

<tr>

<TD width= "height=" > Username </td>

<TD width= "162" ><input name= "user" type= "text" id= "user"/></td>

</tr>

<tr>

<TD height= "@" > Password:</td>

<td> <input name= "pwd" type= "text" id= "pwd"/></td>

</tr>

<tr>

<TD height= "colspan=" 2 "align=" center "><input name=" button "type=" button "class=" Btn_grey "value=" Login " onclick= "Check ()"/>

<input name= "Submint2" type= "reset" class= "Btn_grey" value= "reset"/>

</td>

</tr>

</table>

</form>

<script type= "Text/javascript" >

/*

P243 14-3

P246 14-6

The P251 14-8 interface implements the recommended form approach.

*/

var num1=120,num2=25;

document.write ("120+25=" + (num1+num2) + "<BR >");

document.write ("120-25=" + (num1-num2) + "<BR >");

document.write ("120*25=" + (num1*num2) + "<BR >");

document.write ("120/25=" + (num1/num2) + "<BR >");

document.write ("(120++)" + (num1++) + "<BR >");

document.write ("(++120) =" + (++NUM1) + "<BR >");

var a=3;

var b= "name";

var c=null;

Alert ("A is of type:" + (typeof a) + "\nb of type:" + (typeof B) + "\NC type:" + (typeof c));

function Check ()

{

var Name=form1.user.value;

var Pwd=form1.pwd.value;

if (name== "") | | (Name=null))

{

Alert ("Please enter user name");

Form1.user.focus ();

Return

}

else if ((pwd== "") | | (Pwd=null))

{

Alert ("Please enter password");

Form1.pwd.focus ();

Return

}

Else

{

Form1.submit ();

}

}

</script>

<body>

</body>

Two

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

<title> Untitled Document </title>

<script type= "Text/javascript" >

/*

P258 14-13 Learning function Countdown,

1 understand the parameter passing implementation, master the "id" attribute as the use of the argument.

2 learning the use of date

3 trying to rewrite the countdown into a switch---case condition judgment

The 4 page implementation is converted into a form format.

*/

function Countdown (Title,intime,divid)

{

var online=new Date (Intime);

var now=new Date ();

var leave =online.gettime ()-now.gettime ();

var Day=math.floor (leave/(1000*60*60*24)) +1;

if (day>=0)

{

Switch (day)

{

Case 0:divid.innerhtml= "<b> is Today" +title+ "! </b> "; break;

Case 1:divid.innerhtml= "<b>-Tomorrow is" +title+ "! </b> "; break;

Default:d ivid.innerhtml= "<b>-according to" +title+ "and" +day+ "Day! </b> "; break;

}

}

Else

{

Divid.innerhtml= "<b>-oops" +title+ "is over!" </b> ";

}

}

</script>

<body>

<table width= "height=" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >

<tr>

<TD valign= "Bottom" ><table width= "346" height= "418" border= "0" cellpadding= "0" cellspacing= "0" >

<tr>

<TD width= > </td>

<TD width= ">"

<div id= "Countdown" >

<b>-</b></div>

<script type= "Text/javascript" >

Countdown ("2016 Mother's Day", "5/8/2016", Countdown);

</script>

</td>

</tr>

</table></td>

</tr>

</table>

</body>

C Language Case:

303.cpp:defines the entry point for the console application.

//

#include "stdafx.h"

#include <stdio.h>

#include <string.h>

typedef char DataType;

struct element//node definition

{

DataType data;

Float weight;//The weight of this character

int Parent,lchild, rchild;//parent node, left child, right child storage location

};

#define MAXLEAF 6//maximum number of leaf nodes, number of characters to encode

#define MAXNODE maxleaf*2-1//Maximum node count

struct huffmancode{

DataType ch;//Store characters

Char bits[maxleaf];//a Huffman encoding for storing characters

};

Huffmancode Hcode[maxleaf];

Element ht[Maxnode];

This function is to select the location of the two smallest weight nodes, respectively, in pn[0],pn[1]

void Select (element *pt,int n, int *pn) {

int i,iposi=0;

float tmp;

for (i=0;i<n;i++) {

if (pt[i].parent==-1)

{

Tmp=pt[i].weight;pn[0]=i;

Iposi=i;

Break

}

}

for (i=iposi;i<n;i++) {

if (tmp>pt[i].weight && pt[i].parent==-1) {

Pn[0]=i; Tmp=pt[i].weight;

}

}

for (i=0;i<n;i++) {

if (Pt[i].parent==-1 && i!=pn[0])

{

Tmp=pt[i].weight;pn[1]=i;

Iposi=i;

Break

}

}

for (i=iposi;i<n;i++) {

if (tmp>pt[i].weight && pt[i].parent==-1 && i!=pn[0]) {

Pn[1]=i; Tmp=pt[i].weight;

}

}

Return

}

This function functions to create a Huffman tree

void Createhuffmantree (element *pt) {

int i,k=0;

int pn[2];

for (i=maxleaf; i<maxnode;i++) {

Select the location of the two smallest weight nodes, respectively, in pn[0],pn[1]

Select (PT,MAXLEAF+K,PN);

k++;

pt[pn[0]].parent=pt[pn[1]].parent=i;

PT[I].LCHILD=PN[0]; PT[I].RCHILD=PN[1];

Pt[i].weight=pt[pn[0]].weight+pt[pn[1]].weight;

}

}

This function functions to generate Huffman code

void Createhuffmancode (element *pt,int N) {

int I,p,j,start;

Char Cd[maxnode];

for (i=0;i<n;i++) {

start=n-1;

cd[start]=0;

P=pt[i].parent;

J=i;

From the leaf knot point, step by step to the root node, in reverse order to find the Huffman code of each node

while (p!=-1) {//when P is 1, it means traversing to the root node.

if (PT[P].LCHILD==J)

cd[--start]= ' 0 ';//left child coded to 0

Else

cd[--start]= ' 1 '; Right child coded to 1

I=s;

P=pt[p].parent;

}

strcpy (Hcode[i].bits,&cd[start]);

}

}

int main (int argc, char* argv[])

{

printf ("303 Liu Xiaoya \ n");

Element Ht[maxnode];

int i;

for (i=0;i<maxnode;i++) {

Ht[i].parent=-1;

Ht[i].lchild=-1;

Ht[i].rchild=-1;

Ht[i].data= ";

ht[i].weight=0;

}

Ht[0].data= ' A '; ht[0].weight=2; Hcode[0].ch=ht[0].data;

Ht[1].data= ' B '; ht[1].weight=4; Hcode[1].ch=ht[1].data;

Ht[2].data= ' C '; ht[2].weight=5; Hcode[2].ch=ht[2].data;

Ht[3].data= ' D '; ht[3].weight=3; Hcode[3].ch=ht[3].data;

Ht[0].data= ' A '; ht[0].weight=28; Hcode[0].ch=ht[0].data;

Ht[1].data= ' B '; ht[1].weight=13; Hcode[1].ch=ht[1].data;

Ht[2].data= ' C '; ht[2].weight=30; Hcode[2].ch=ht[2].data;

Ht[3].data= ' D '; ht[3].weight=10; Hcode[3].ch=ht[3].data;

Ht[4].data= ' E '; ht[4].weight=12; Hcode[4].ch=ht[4].data;

Ht[5].data= ' F '; ht[5].weight=7; Hcode[5].ch=ht[5].data;

Createhuffmantree (HT);//Generate Huffman Tree

Createhuffmancode (ht,maxleaf);//Generate Huffman code

Output encoding for each character

float weight=0;

for (i=0;i<maxleaf;i++) {

Weight +=ht[i].weight*strlen (hcode[i].bits);

printf ("Character =%c weights =%f encoded =%s\n", hcode[i].ch, ht[i].weight,hcode[i].bits);

}

printf ("weight=%f\n", weight);

return 0;

}

Weekly Summary <4>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.