Ⅰ c語言 密碼字典
樓上的兄弟不適合做程序員,自私!
樓主,12位的密碼你知道有多少了嗎?這數據量非常大,程序我是寫出來了,10位還能用文本打開,但是到了12位就打不開了,120多M的txt,反正我電腦打開的時候就卡死了!有疑問網路找我!
其實程序很簡單。
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
int main()
{
/*to char +48*/
FILE *f;
char a[13];
int i1,i2,i3,i4,i5,i6,i7,i8;
f= fopen("C:\\mima.txt","wt+");
printf("create...\n ");
a[0] = 'l';
a[1] = 'X';
a[2] = '1';
a[3] = 'v';
a[112] = '\n';
for(i1=0;i1<10;i1++)
{
a[4]=i1+48;
for(i2=0;i2<10;i2++)
{
a[5]=i2+48;
for(i3=0;i3<10;i3++)
{
a[6]=i3+48;
for(i4=0;i4<10;i4++)
{
a[7]=i4+48;
for(i5=0;i5<10;i5++)
{
a[8]=i5+48;
for(i6=0;i6<10;i6++)
{
a[9]=i6+48;
for(i7=0;i7<10;i7++)
{
a[10]=i7+48;
for(i7=0;i7<10;i7++)
{
a[11]=i8+48;
fwrite(a,13,1,f);
}
}
}
}
}
}
}
}
fclose(f);
printf("success!\n");
getch();
}
Ⅱ python中有C語言嗎
1.C語言是編譯語言,Python是腳本語言。說是C語言會比Python快
2.list和數組
C語言中的數組,裡面的都是數字,而list中可以包含很多不同的數據元素。
2.import和include
在C語言中使用那個庫函數,需要引入頭文件用include引入,而在python中需要引入別的模塊或者函數時需要用import引入。
兩者的不同機制是,C語言中include是告訴預處理器,這個include指定的文件的內容,要當作本地源文件出現過,而python中的import可以通過簡單的import
導入,或者是 import numpy as np
3.全局變數方面
在C語言中,聲明全局變數,如果值是恆定的,那麼可以直接用#define聲明,如果只是聲明全局,並且變數的值是可變的,那麼直接類似int a
就可以了,在python中,聲明全局變數時,需要加上global,類似global a,在函數裡面使用的時候需要先聲明global a
,否則直接用a那麼python會重新創建一個新的本地對象並將新的值賦值給他,原來的全局變數的值並不變化
Ⅲ 跪求關於詞典檢索的c語言程序 幫幫忙啊!!!!!!!
原型:
int WINAPI icePub_dictionaryCodeTransfer2(char *strDictionaryFilename,char *strSrc,char *strCode,char *strFenge)
輸入:strDictionaryFilename 字典文件名
strSrc 待處理單詞
strFenge 字典里單詞和code之間的分隔符字元串
輸出:strCode strSrc對應信息
返回碼:
char strCode[1024];
typedef int (WINAPI ICEPUB_DICTIONARYCODETRANSFER2)(char *strDictionaryFilename,char *strSrc,char *strCode,char *strFenge);
ICEPUB_DICTIONARYCODETRANSFER2 *icePub_dictionaryCodeTransfer2 = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_dictionaryCodeTransfer2 = (ICEPUB_DICTIONARYCODETRANSFER2 *)GetProcAddress(hDLLDrv, "icePub_dictionaryCodeTransfer2");
}
if(icePub_dictionaryCodeTransfer2)
icePub_dictionaryCodeTransfer2("漢英字典.txt","我",strCode, " ");
if(hDLLDrv)
FreeLibrary(hDLLDrv);
AfxMessagBox(strCode);
Ⅳ 急急急!!!!用c語言實現字典 要求:用無序雙向循環鏈表實現字典的基本操作如下
#include <stdafx.h> //這行是VC編譯時要的頭文件,你若TC就不要本行了
#include <stdio.h>
typedef struct dictnode{char *key; char *value; dictnode *pre; dictnode *next;} DictNode;
DictNode *pHead = NULL;
//(1)make:構造空的字典
int make()
{
if(pHead)return -1;
pHead = (DictNode*)malloc(sizeof(DictNode));
memset(pHead,0,sizeof(DictNode));
pHead->pre = pHead;
pHead->next = pHead;
return 0;
}
//(2)size:返回字的字典中記錄數
int size()
{
int i;
DictNode*p;
for(i=0,p=pHead; p->next!=pHead; p=p->next,i++);
return i;
}
//(3)IsEmpy:如果字典為空則返回真,否則返回假
int IsEmpy()
{
return (pHead->pre==pHead);
}
//(4)Clear:將字典重置為空
void Clear()
{
DictNode* p,*ptmp;
for(p=pHead->next; p!=pHead ; )
{
ptmp = p;
p = p->next;
free(ptmp->key);
free(ptmp->value);
free(ptmp);
}
pHead->next = pHead->pre = pHead;//最後一個空節點也是第一個節點
}
//(5)Insert:插入記錄到字典
int Insert(char *key,char*value)
{
DictNode* p, *ptmp;
if(!key||!value||!*key||!*value) return -100;//調用錯誤
ptmp = (DictNode*)malloc(sizeof(DictNode));
if(!ptmp) return -2; //內存不足這種極端的情況很難出現,但有可能
memset(ptmp,0,sizeof(DictNode));
ptmp->key =(char*) malloc(strlen(key)+1);
if(!ptmp->key){free(ptmp);return -2;} //內存不足這種極端的情況很難出現,但有可能
strcpy(ptmp->key,key);
ptmp->value = (char*)malloc(strlen(value)+1);
if(!ptmp->value){free(ptmp->key);free(ptmp); return -2;} //內存不足這種極端的情況很難出現,但有可能
strcpy(ptmp->value,value);
for(p=pHead->next; p->next!=pHead; p=p->next) if(p->key&&!strcmp(p->key,key)) return 1;//記錄存在,插入失敗
ptmp->next = pHead; pHead->pre = ptmp;
ptmp->pre = p; p->next = ptmp;
return 0;//操作成功返回0
}
//(6)remove:與給定關鍵字的記錄相同則刪除,該記錄被返回,否則字典保持不變
DictNode* remove(char *key)
{
DictNode* p;
for(p=pHead->next; p!=pHead&&strcmp(p->key,key); p=p->next);
if(p==pHead) return NULL;
p->pre->next = p->next;
p->next->pre = p->pre;
p->pre = p->next = NULL;
return p;//結點p的空間(key value p三個)沒有釋放,外面要接收返回值並主動釋放結點空間或做別的處理如插入另一表中等
}
//(7)IsPrensent:如果存在與給定關鍵字匹配的記錄則返回真,否則返回假
int IsPrensent(char *key)
{
DictNode* p;
for(p=pHead->next; p!=pHead&&strcmp(p->key,key); p=p->next);
return (p!=pHead);
}
//(8)Find:如果存在與給定關鍵字相同的記錄,則返回記錄;如果沒有找到,則返回空
DictNode* Find(char *key)
{
DictNode* p;
for(p=pHead->next; p!=pHead&&strcmp(p->key,key); p=p->next);
if(p==pHead) return NULL;
return p; //不要對Find返回的記錄key值做變更,value值可以修改,value加長時要重新分配空間。因為記錄還在字典鏈表中
}
void main()
{
const char *prtstr = "****************************";
DictNode* ptmp;
char keybuf[80];
char valuebuf[1024];
int c;
make();
while(1)
{
system("cls");//清屏
printf("%s 選擇菜單 %s",prtstr,prtstr);
printf("\n\tF---詞條查找\n\tI---插入新詞條\n\tR---刪除詞條\n\tC---清空字典\n\tS---顯示字典詞條數\n\tQ---退出\n");
printf("請選擇操作菜單:");
fflush(stdin);
c = getchar();
if(c>='a'&&c<='z') c -= ('a'-'A');//換大寫
if(c!='F'&&c!='I'&&c!='R'&&c!='C'&&c!='S'&&c!='Q') continue;
fflush(stdin);
switch(c)
{
case 'F':
printf("詞條查找:\n請輸入Key值:");scanf("%s",keybuf);
fflush(stdin);
ptmp = Find(keybuf);
if(ptmp){printf("Key:%s Value:%s",ptmp->key,ptmp->value);}
else{printf("沒找到詞條:%s,你可以先選擇插入這個新詞條",keybuf);}
break;
case 'I':
printf("插入新詞條:\n請輸入Key值:");scanf("%s",keybuf);
fflush(stdin);
if(IsPrensent(keybuf)){printf("詞條%s已存在\n",keybuf);}
else
{
printf("請輸入它的解釋:");gets(valuebuf);
if(!Insert(keybuf,valuebuf))printf("插入成功\n");
else printf("插入失敗\n");
}
break;
case 'R':
printf("刪除詞條:\n請輸入Key值:");scanf("%s",keybuf);
fflush(stdin);
ptmp = remove(keybuf);
if(ptmp)
{
free(ptmp->value);free(ptmp->key);free(ptmp);
printf("記錄key:[%s]已刪除\n",keybuf);
}
else
printf("未找到待刪除的記錄key:[%s]\n",keybuf);
break;
case 'C':
printf("清空字典:\n真的要清嗎?\n請輸入Yes以確認刪除操作(首字母大寫):");scanf("%s",keybuf);
fflush(stdin);
if(strcmp(keybuf,"Yes")){printf("放棄了清空操作\n");}
else {Clear();printf("Ok,你堅持操作,現在字典已清空了\n");}
break;
case 'S':
printf("顯示字典詞條數:\n當前詞條總數:%d\n", size());
break;
case 'Q':
Clear(); free(pHead);
printf("Byebye");
exit(0);
}
printf("\n按回車鍵繼續......");
fflush(stdin);
getchar();
}
}
//VC7.1 下調試通過,運行功能正常
Ⅳ 求一個實現簡單的英漢詞典(30詞左右)c++的C語言程序
字典最快速的實現方法是trie tree。
這個樹是專門用來實現字典的。但是trie tree的刪除操作比較麻煩。用二叉查找樹可以實現,速度也可以很快。AVL tree只不過是平衡的二叉樹,在字典這個應用上沒有客觀的速度提升,因為字典不會產生極端化的二叉樹(鏈表)。
下面是我的二叉查找樹的代碼。二叉查找樹的優點是實現容易,而且它的inorder traverse既是按照字母順序的輸出。
//binary search tree, not self-balancing
//by Qingxing Zhang, Dec 28,2009. prep for google interview
#include <iostream>
using namespace std;
struct BST
{
int data;
BST *left;
BST *right;
};
//runtime: O(logn) on average, O(n) worst case
bool search(BST *&root, int key)//return false if the key doesn't exist
{
if(root==NULL)
return false;
if(key < root->data)
return search(root->left,key);
else if(key > root->data)
return search(root->right,key);
else
return true;
}
//runtime: O(logn)on average, O(n) worst case
bool insert(BST *&root, int key)//return false if the key already exists
{
if(root==NULL)
{
BST *node = new BST;
node->data = key;
node->left = node->right = NULL;
root = node;
return true;
}
else if(key < root->data)
return insert(root->left,key);
else if(key > root->data)
return insert(root->right,key);
else
return false;
}
//runtime:O(logn) on average, O(n) worst case
bool remove(BST *&root,int key)//return false if the key doesn't exist.
{
if(root==NULL)//no such key
return false;
else if(key < root->data)
return remove(root->left,key);
else if(key > root->data)
return remove(root->right,key);
else//node found
{
if((root->left==NULL)&&(root->right==NULL))//no child(leaf node)
{
BST *tmp = root;
root = NULL;
delete tmp;
}
else if((root->left==NULL)||(root->right==NULL))//one child
{
BST *tmp = root;
if(root->left==NULL)
root = root->right;
else
root = root->left;
delete tmp;
}
else//two children:replace node value with inorder successor and delete that node
{
BST *tmp = root->right;
while(tmp->left!=NULL)
tmp = tmp->left;
int tmpdata = tmp->data;
remove(root,tmpdata);
root->data = tmpdata;
}
return true;
}
}
//runtime:O(n)
void inorder(BST *&node)
{
if(node!=NULL)
{
inorder(node->left);
cout << node->data << " ";
inorder(node->right);
}
}
//runtime:O(n)
void preorder(BST *&node)
{
if(node!=NULL)
{
cout << node->data << " ";
preorder(node->left);
preorder(node->right);
}
}
//runtime:O(n)
void postorder(BST *&node)
{
if(node!=NULL)
{
postorder(node->left);
postorder(node->right);
cout << node->data << " ";
}
}
int main()
{
bool b;
BST *root = NULL;
b = insert(root,1);
b = insert(root,3);
b = insert(root,7);
b = insert(root,5);
b = insert(root,77);
b = insert(root,10);
b = insert(root,4);
b = insert(root,13);
//inorder
cout << "In-order:";
inorder(root);
cout << endl;
//preorder
cout << "Pre-order:";
preorder(root);
cout << endl;
//postorder
cout << "Post-order:";
postorder(root);
cout << endl;
// search for 7
if(search(root,7))
cout << "7 found!" << endl;
else
cout << "7 doesn't exist!" << endl;
b = remove(root,7);
cout << "----------------" << endl;
//inorder
cout << "In-order:";
inorder(root);
cout << endl;
//preorder
cout << "Pre-order:";
preorder(root);
cout << endl;
//postorder
cout << "Post-order:";
postorder(root);
cout << endl;
if(search(root,7))
cout << "7 found!" << endl;
else
cout << "7 doesn't exist!" << endl;
return 0;
}
Ⅵ 急!!十萬火急!!!高手的來!關於數據結構中字典的實現,C語言代碼:用無序循環單鏈表實現以下操作!
printarray(b,lenth);
printf("\n");
free(a);
free(b);
return 0;
}
void inputarray(int*a,int n){
for(int j=0;j<n;j++)
scanf("%d",&a[j]);
}
void exchange(int*a,int*b,int n){
for(int j=0;j<n;j++)
swap(a+j,b+j);
}
void swap(int* a,int* b){
int c;
c=*a;
*a=*b;
*b=c;
}
void printarray(int* a,int n){
for(int j=0;j<n;j++)
printf("%d,",a[j]);
Ⅶ C語言實現字典序排列的代碼問題
一般的排序是從0位置開始,即從數組第一個元素開始排序。
你這段代碼是從第n+1個數據開始排序,僅此而已
Ⅷ 需要會C語言的各位大佬幫忙寫一個簡單的詞典小代碼
有償的 30元 一天寫完
Ⅸ C語言簡單的英文詞典排版系統的實現
#include "stdio.h" #include "stdlib.h" #include "string.h" #include "ctype.h" #define ROWS 256 #define COLS 32 static FILE *fp; static char a[ROWS][COLS]; char get_option(void); int b(int count); void c(char *pt[], int count); int check(char arr[], int count); void storage(char *pt[], int count); int main(void) { int i,count; int start; char *pt[ROWS]; char ch, len; char input; if((fp=fopen("words.txt","a+"))==NULL) { fputs("不能打開或建立文件!\n",stderr); exit(1); } fseek(fp,0L,SEEK_END); start=(int)ftell(fp)/32; count=start; rewind(fp); if(fread(a,32*sizeof(char),start,fp)==0) { i=0; puts("請輸入單詞(每行一個),在新行輸入END結束輸入:"); while(i<ROWS&&scanf("%s", a[i])==1) { fflush(stdin); if(strncmp(a[i],"END",3)==0) { count+=i; break; } if(check(a[i], i)) continue; i++; } } puts("您要做些什麼?"); puts("a. 顯示已有的單詞 b. 添加新單詞"); puts("c. 對已有的單詞進行排序 d. 退出"); while((input=get_option())!='d') { if(input=='a') { puts("已有的單詞:"); for(i=0;i<count;i++) { printf(" "); puts(a[i]); } } if(input=='b') { puts("請輸入新的單詞(每行一個),在新行輸入END結束輸入: "); count=b(count); } if(input=='c') { puts("對單詞進行排序:"); c(pt, count); for(i=0;i<count;i++) { printf(" "); puts(pt[i]); } } puts("還要做些什麼?"); } storage(pt,count); fclose(fp); puts("再見!"); return 0; } char get_option(void) { char ch; while((ch=getchar())<'a'||ch>'d') { while((ch=getchar())!='\n') ; puts("請輸入a,b,c或者d."); } fflush(stdin); return ch; } int b(int count) { int i; i=count; while(i<ROWS&&scanf("%s", a[i])==1) { fflush(stdin); if(check(a[i], i)) continue; if(strncmp(a[i],"END",3)==0) { count=i; break; } i++; } return count; } void c(char *pt[], int count) { int i,j; char *temp; for(i=0;i<ROWS;i++) pt[i]=a[i]; for(i=0;i<count;i++) for(j=i+1;j<count;j++) { if(strcmp(pt[i],pt[j])>0) { temp=pt[i]; pt[i]=pt[j]; pt[j]=temp; } } } int check(char arr[], int count) { int i; int flag=0; for(i=0;i<strlen(arr);i++) if(isalpha(arr[i])==0) { printf("%s不是一個單詞.\n",arr); flag=1; break; } for(i=0;i<count;i++) if(strncmp(a[i],a[count],strlen(a[count])+1)==0) { puts("重復的單詞!"); flag=1; } return flag; } void storage(char *pt[], int count) { int i,j; char ptr[ROWS][COLS]; c(pt, count); for(i=0;i<count;i++) for(j=0;pt[i][j]!='\0';j++) ptr[i][j]=pt[i][j]; fp=fopen("words.txt","w+"); rewind(fp); fwrite(ptr,32*sizeof(char),count,fp); }
Ⅹ 運用c語言編寫一個英漢字典~ 謝謝啦~先
原型:
int WINAPI icePub_dictionaryCodeTransfer2(char *strDictionaryFilename,char *strSrc,char *strCode,char *strFenge)
輸入:strDictionaryFilename 字典文件名
strSrc 待處理單詞
strFenge 字典里單詞和code之間的分隔符字元串
輸出:strCode strSrc對應信息
返回碼:
原型:
int WINAPI icePub_dictionaryAddRecord(char *strDictionaryFilename,char *strSrc,char *strCode,char *strFenge)
輸入:strDictionaryFilename 字典文件名
strSrc 待添加單詞(如果存在則替換)
strCode strSrc對應信息
strFenge 字典里單詞和code之間的分隔符字元串
輸出:
返回碼:
原型:
int WINAPI icePub_dictionaryDelRecord(char *strDictionaryFilename,char *strSrc,char *strFenge)
輸入:strDictionaryFilename 字典文件名
strSrc 待刪除單詞
strFenge 字典里單詞和code之間的分隔符字元串
輸出:
返回碼:
網路一個《icepubdll揭秘》有詳細說明