本文目录一览:
谁能帮我做下这个C语言程序,感激不尽
//Problem 1
#include stdio.h
#include math.h
int arraycheck(int * s){
if (s[0] == s[1] s[3] == s[4] s[0] != s[4])
return 1;
else
return 0;
}
int main(){
int license[5];
int i,j;
int n;
// d
for (i = 100; i = 333; i++)
{
n = i*i;
j = 0;
do{
license[j++] = n %10;
}
while((n/=10)0);
if (arraycheck(license))
printf ("The license is dex %d and the dex number is %d \n", i*i, i);
}
// x
for (i = 256; i 1024; i++)
{
n = i*i;
j = 0;
do{
license[j++] = n %16;
}
while((n/=16)0);
if (arraycheck(license))
printf ("The license is hex %x and the hex number is %x \n", i*i,i);
}
// o
for (i = (int)(64*(double)sqrt(2)) - 1; i (int)(128*(double)sqrt(2)) + 1; i++)
{
n = i*i;
j = 0;
do{
license[j++] = n %8;
}
while((n/=8)0);
if (arraycheck(license))
printf ("The license is oct %o and the oct number is %o\n", i*i, i);
}
return 0;
}
//Press ENTER or type command to continue
//The license is dex 22500 and the dex number is 150
//The license is dex 44100 and the dex number is 210
//The license is hex 44100 and the hex number is 210
//The license is hex 55900 and the hex number is 250
//The license is hex 77499 and the hex number is 2bb
//The license is oct 22000 and the oct number is 140
//The license is oct 33144 and the oct number is 166
//The license is oct 44100 and the oct number is 210
//The license is oct 55100 and the oct number is 230
//Problem 2
#include stdio.h
#include stdlib.h //header file for malloc
// header
typedef struct element * Element;
typedef struct element * List;
//typedef int Item;
struct element{
char item1;
char item2;
Element next;
};
// header_end
// init linked list; dummy head, NULL tail
void init(List list)
{
list-next = NULL;
}
//push element into linked list
void push(List list, Element item){
item-next = list-next;
list-next = item;
}
//print current list
void print(List list){
Element curr;
for ( curr = list-next; curr != NULL; curr=curr-next){
printf("%c %c\n",curr-item1,curr-item2);
}
}
//code char
char charcode(List list, char c)
{
Element curr=(Element)malloc(sizeof(Element));
curr=list;
while(curr != NULL)
{
if (curr-item1 == c){
return curr-item2;
free(curr);
break;
}
curr = curr -next;
}
free(curr);
return '\0';
}
//decode char
char chardecode(List list, char c)
{
Element curr=(Element)malloc(sizeof(Element));
curr=list;
while(curr != NULL)
{
if (curr-item2 == c){
return curr-item1;
free(curr);
break;
}
curr = curr-next;
}
free(curr);
return '\0';
}
//update the linked list with array source and key
void update(List list, char *source, char *key){
int i;
for (i = 0; i 32; i++){
// new element
Element new;
new = (Element)malloc(sizeof(Element));
new-item1 = source[i];
new-item2 = key[i];
//add new element
push(list, new);
}
}
// check if the char is among the source
int charcheck( char * source, int c)
{
int i;
for (i = 0; i 32; i++)
if (c == source[i]){
return 1;
break;}
return 0;
}
int main()
{
// source array and key array
char source[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ .,?!;"};
char key[] = {"?Q.W,EMRNTBXYUV!ICO PZA;SDLFKGJH"};
//Initial list
//Dummy head, NULL tail
List list;
list = (List)malloc(sizeof(List));
init(list);
//update the link list with the source and key array
update(list,source,key);
//HMI
printf("Pls select the work mode, 1 for code | 0 for decode\n");
int mode;//mode 1:code 0:decode
do{
scanf("%d",mode);
if (mode == 1){
printf("Code mode\n");
}else if(mode == 0){
printf("Decode mode\n");
}else{
printf("%d is invalid mode, pls input the correct mode:\n",mode);
}
}
while(mode != 1 mode != 0);
//start input
printf("Pls input the word and end with Enter\nIf you want to exit input EOF(Ctrl+D)\n");
int c;
// int caseflag = 1; // 1: Capital 0:lower
while ((c = getchar()) != EOF){
if (c = 'a' c = 'z') // lower case to Capitial case
{
c = c + 'A'-'a';
// caseflag = 0;
}
switch(mode){
case 1: // code
if (charcheck(source,c))
{
if(charcode(list,c) = 'A' charcode(list,c)='Z')
putchar(charcode(list,c) + 'a'-'A');
else
putchar(charcode(list,c));
}
break;
case 0: //decode
if (charcheck(source,c))
{
if(chardecode(list,c) = 'A' chardecode(list,c)='Z')
putchar(chardecode(list,c) + 'a'-'A');
else
putchar(chardecode(list,c));
}
break;
default:
exit(1);
break;
}
}
return 0;
}
c语言中 char code *s 是什么意思
程序可以简单的分为code(程序)区,和data
(数据)区,code区在运行的时候是不可以更改的,data区放全局变量和临时变量,是要不断的改变的,cpu从code区读取指令,对data区的数据进行运算处理。
code的作用是告诉单片机,我定义的数据要放在rom(程序存储区)里面,写入后就不能再更改。
所以说,
char
code
*s
就是定义在rom区的一个字符指针s
AS3中charCode!=0是什么意思啊
charCode!=0 从字面上看是指 charCode这个变量的值不是零
然后AS3中如果这句语句是出现在按键侦听事件中的话,e.charCode指的就是外部输入设备按下的键的键值。比如上下左右四个方向键对应的keyCode是38,40 37,39。
c语言哈夫曼树哈夫曼编码纠错
我电脑里保存了类似的这样的题目,可以直接运行的:#include#include#include#include#include#include#defineMAXSIZE50//定义huffnode及huffcode,分别用来存储节点信息及各节点编码typedefstruct{chardata;//节点值intweight;//权值intparent;intleft;intright;intflag;}huffnode;typedefstruct{charcode[MAXSIZE];intstart;}huffcode;huffnodehtree[2*MAXSIZE];huffcodehcode[MAXSIZE];//寻找权值最小的节点intselect(inti){intk=32767;intj,q;for(j=0;j=i;j++){if(htree[j].weight