int main() { char s[NR]; int n,p; scanf("%d %d",&n,&p); scanf("%s",s); stergere(s,n,p); printf("%s",s); return 0; }j
void numaratoare ( nod *& prim, nod *& ultim, unsigned & n ) { nod *p,*q; int k; while ( n>0 ) { cout<<"k= "; cin>>k; p=prim; for ( int i=1; i < k; i++ ) p=p->adr; q=p; p=p->adr; cout<<"copilul "<<q->copil<<" este scos din joc"<<endl; stergere ( prim, ultim, q, n ); } cout<<"Nu a mai ramas nici un copil in joc!!!"; }
int main() { int i,n,j,v[40],ok,aux,k; //scanf("%d",&n); n=9; v[1]=16; v[2]=21; v[3]=3; v[4]=14; v[5]=15; v[6]=9; v[7]=8; v[8]=4; v[9]=24; for (i=1;i<=n;i++) { //scanf("%d",&v[i]); k=i; while (k/2>=1) { if (v[k]>v[k/2]) { aux=v[k]; v[k]=v[k/2]; v[k/2]=aux; } else break; k=k/2; } } printf("\n"); for (i=1;i<=n;i++) { printf("%d ",v[i]); } printf("\n"); aux=n; for (i=1;i<=aux;i++) { printf("%d ",stergere(v,&n)); /*for (j=1;j<=n;j++) { printf("%d ",v[j]); }*/ } getch(); return 0; }
void stergere(radix*rad) { if (rad != NULL) { int i; for (i = 0; i < rad->nr_fii; i++) { //fprintf(fis2,"\n"); stergere((rad->next)[i]); } if(i>=rad->nr_fii)free(rad); } }
listad *stergere_negative(listad *q){ listad *p = q; FILE *f; int k=1; f = fopen("lista.txt","w"); while(p){ if(p->inf<0){ p = p->next; q = stergere(q,k); }else{ fprintf(f,"%d ",p->inf); p = p->next; k++; } } fclose(f); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static int ok = 0; static int nr_fis_intrare = 0; static int nr_fis_iesire = 0; switch (msg) { case WM_CREATE: { //text static 1 HWND statik = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE|SS_CENTER, 60, 10, 300, 200, hwnd, NULL, NULL, NULL); SetWindowText( statik, "Introduceti textul pentru prelucrare!!" ); // //text static nr2 HWND statik2 = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE|SS_CENTER, 60, 260, 300, 200, hwnd, NULL, NULL, NULL); SetWindowText( statik2, "Arborele radix corespunzator este:" ); //caseta text nr 1 HFONT hfDefault; hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 40, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR); //caseta text nr 2 HFONT hfDefault2; hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 280, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR); //caseta taext 3 HFONT hfDefault3; hEdit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 410, 350, 200, 100, hwnd, NULL, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR); //buton 1 CreateWindow("BUTTON", "Afisare arbore", WS_BORDER | WS_CHILD | WS_VISIBLE, 410, 300, 250, 50, hwnd, (HMENU)Buton_Afisare, NULL, NULL); // //buton 2 CreateWindow("BUTTON", "Apasati pentru a prelucra textul!", WS_BORDER | WS_CHILD | WS_VISIBLE, 410, 50, 250, 50, hwnd, (HMENU)Buton_prelucrare, NULL, NULL); LoadTextFileToEdit(hEdit,"f.txt"); } break; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_FILE_OPEN: { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if (GetOpenFileName(&ofn)) { // Do something usefull with the filename stored in szFileName MessageBox(hwnd, szFileName, "Ati ales", MB_OK | MB_ICONEXCLAMATION); static char text[100]; LoadTextFileToEdit(hEdit, szFileName); } } break; case ID_FILE_SAVE: { int val=0; val = GetWindowText(hEdit, &textSaved[0], 20000); MessageBox(hwnd, textSaved, "Salvati urmatorul text:", MB_OK | MB_ICONEXCLAMATION); OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if (GetOpenFileName(&ofn)) { // Do something usefull with the filename stored in szFileName MessageBox(hwnd, szFileName, "Text Salvat in:", MB_OK | MB_ICONEXCLAMATION); } SaveTextFileFromEdit(hEdit, szFileName); } break; case ID_START: { } break; case Buton_prelucrare: { int k = 1; SetWindowText(hEdit2, ""); if (SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0) == 0) // then field is empty { MessageBox(hwnd, "Nu ati introdus text!", "Atentionare!", MB_OK | MB_ICONERROR); SetWindowText(hEdit3, ""); //golire textbox3 FILE*f = fopen("f.txt", "wt"); fputs("Introduceti text!", f); LoadTextFileToEdit(hEdit, "fis.txt"); fclose(f); } else { SaveTextFileFromEdit(hEdit, "fis.txt"); char cuv[100]; inserare(rad, '*'); FILE*fis = fopen("fis.txt", "rt"); FILE*fis2; while (!feof(fis)) { fscanf(fis, "%s", cuv); functie(cuv, rad); } fseek(fis, 0, 0); nr_fis_intrare = nr_caractere(fis); fclose(fis); fis2 = fopen("f.txt", "wt"); afisare(fis2, 0, rad); fclose(fis2); fis2 = fopen("f.txt", "rt"); fseek(fis, 0, 0); nr_fis_iesire = nr_caractere(fis2); fclose(fis2); stergere(rad); rad = NULL; ok = 1; MessageBox(hwnd, "Textul a fost prelucrat cu succes!", "Atentionare!", MB_OK | MB_ICONINFORMATION); } } break; case Buton_Afisare: { if (ok == 1) { ok = 0; MessageBox(hwnd, "Textul a fost transformat cu succes!!", "Atentionare!", MB_OK | MB_ICONINFORMATION); LoadTextFileToEdit(hEdit2, "f.txt"); // FILE*fis = fopen("f.txt", "wt"); fprintf(fis, "Numar initial:%d\n", nr_fis_intrare); fprintf(fis, "Numar comprimat:%d\n", nr_fis_iesire); int x = 100 - ((nr_fis_iesire*100/nr_fis_intrare)); fprintf(fis, "Procentul de eficienta: %d", x); fprintf(fis,"%c", '%'); fclose(fis); LoadTextFileToEdit(hEdit3,"f.txt"); fis = fopen("f.txt", "wt"); fclose(fis); } else { MessageBox(hwnd, "Textul nu a fost prelucrat anterior!!", "Atentionare!", MB_OK | MB_ICONSTOP); SetWindowText(hEdit3, ""); } FILE*fis = fopen("f.txt", "wt"); fputs("Introduceti text!", fis); LoadTextFileToEdit(hEdit, "fis.txt"); fclose(fis); fis = fopen("fis.txt", "wt"); fclose(fis); } break; case ID_CLEAR: { SetWindowText(hEdit,""); SetWindowText(hEdit2, ""); SetWindowText(hEdit3, ""); } break; } break; case WM_SIZE: { HWND hEdit; RECT rcClient; GetClientRect(hwnd, &rcClient); hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT); SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }