本文目錄一覽:
誰能幫我做下這個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
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/248354.html