Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- zad 1.
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- int main()
- {
- string linia;
- fstream plik;
- fstream plik2;
- plik.open( "plik.txt", ios::in );
- plik2.open( "plik2.txt", ios::out | ios::trunc );
- string a;
- string b;
- cout << "Podaj szukany tekst: ";
- cin >> a;
- cout << "Zamien na: ";
- cin >> b;
- int n;
- if( plik.good() == true and plik2.good() == true )
- {
- while( !plik.eof() )
- {
- getline( plik, linia );
- do{
- n = linia.find( a, 0 );
- if( n != - 1 )
- {
- linia.replace( n, a.size(), b );
- }
- }while (n!=-1);
- plik2 << linia << endl;
- cout << linia << endl;
- }
- }
- plik.close();
- plik2.close();
- return 0;
- }
- /----------------------------------------------------------------------------------/
- zadanie 2.
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- string lancuch;
- int znaki[123];
- for(int i = 0;i<123;i++ )
- {
- znaki[i]=0;
- }
- fstream plik;
- plik.open("D:\\nazwa.txt", ios::in);
- while (!plik.eof())
- {
- getline(plik, lancuch);
- for(int i = 0; i < lancuch.length()+1;i++)
- {
- if((int)lancuch[i]>64 || (int)lancuch[i]<91)
- {
- ++znaki[(int)lancuch[i]];
- }
- else if((int)lancuch[i]>96 || (int)lancuch[i]<123)
- {
- ++znaki[(int)lancuch[i]];
- }
- }
- }
- plik.close();
- cout<<"Male litery: "<<endl;
- for(int i=96;i<123;i++)
- if(znaki[i]>0)
- cout<<(char)i<<" - "<<znaki[i]<<endl;
- cout<<"Duze litery: "<<endl;
- for(int i=65;i<91;i++)
- if(znaki[i]>0)
- cout<<(char)i<<" - "<<znaki[i]<<endl;
- int suma=0;
- for(int i=65;i<123;i++)
- {
- suma+=znaki[i];
- }
- cout<<"\nSuma znakow: "<<suma<<endl;
- //czestosc wystepowania danego znaku
- cout<<"Male litery: "<<endl;
- for(int i=96;i<123;i++)
- if(znaki[i]>0)
- cout<<(char)i<<" - "<<(double)(((double)znaki[i]*100)/(double)suma)<<"%"<<endl;
- cout<<"Duze litery: "<<endl;
- for(int i=65;i<91;i++)
- if(znaki[i]>0)
- cout<<(char)i<<" - "<<(double)(((double)znaki[i]*100)/(double)suma)<<"%"<<endl;
- return 0;
- }
- /-----------------------------------------------------------------------------------------------------------/
- zadanie .3.
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void policz(char tab[], int rozmiar)
- {
- char tablica[rozmiar];
- char uwaga[5]={'U','W','A','G','A'};
- int ilosc=0;
- //liczenie znakow
- for(int q=0;q<rozmiar-1;q++)
- {
- if(tab[q]!=NULL) ilosc++;
- }
- cout<<"Ilosc znakow: "<<ilosc<<endl;
- //kopiowanie tablicy i dopisanie napisu "uwaga"
- for(int i=0;i<rozmiar-1;i++)
- {
- tablica[i]=tab[i];
- tab[i]=uwaga[i];
- }
- //przeniesienie znakow za napis "uwaga"
- for(int i=0;i<rozmiar-1;i++)
- {
- tab[i+5]=tablica[i];
- if(ilosc+5>rozmiar)
- {
- for(int v = rozmiar-1 ; v>rozmiar-5 ; --v)
- {
- tab[v]='.';
- }
- }
- }
- }
- void display(char tab[], int rozmiar)
- {
- //cout<<"Wyswietl tablice znakow: ";
- for(int i=0;i<rozmiar-1;i++)
- {
- cout<<tab[i];
- }
- cout<<endl;
- }
- int main(int argc, char** argv) {
- int x = 6;
- char tab[x];
- for(int i = 0; i < x-1 ; i++)
- {
- tab[i]=NULL;
- }
- tab[0]='w';
- tab[1]='i';
- tab[2]='t';
- tab[3]='a';
- tab[4]='m';
- tab[5]='y';
- cout<<"Tablica znakow na wejsciu"<<endl;
- display(tab, x);
- policz(tab, x);
- cout<<"Tablica znakow na wyjsciu"<<endl;
- display(tab, x);
- return 0;
- }
- //-------------------------------------------------------------------------
- Zadanie 4.
- #include "stdio.h"
- #include <iostream>
- using namespace std;
- /* Pobierz wartosc A z tabeli lat */
- int tabA(int rok)
- {
- if (rok <= 1582)
- {
- return 15;
- }
- if (rok <= 1699)
- {
- return 22;
- }
- if (rok <= 1899)
- {
- return 23;
- }
- if (rok <= 2199)
- {
- return 24;
- }
- if (rok <= 2299)
- {
- return 25;
- }
- if (rok <= 2399)
- {
- return 26;
- }
- if (rok <= 2499)
- {
- return 25;
- }
- return 0; /* poza zakresem */
- }
- /* Pobierz wartosc B z tabeli lat */
- int tabB(int rok)
- {
- if (rok <= 1582)
- {
- return 6;
- }
- if (rok <= 1699)
- {
- return 2;
- }
- if (rok <= 1799)
- {
- return 3;
- }
- if (rok <= 1899)
- {
- return 4;
- }
- if (rok <= 2099)
- {
- return 5;
- }
- if (rok <= 2199)
- {
- return 6;
- }
- if (rok <= 2299)
- {
- return 0;
- }
- if (rok <= 2499)
- {
- return 1;
- }
- return 0; /* poza zakresem */
- }
- /* oblicz ile dni po 22 marca przypada wielkanoc */
- int wielkanoc(int rok)
- {
- int a, b, c, d, e;
- a = rok % 19;
- b = rok % 4;
- c = rok % 7;
- d = (a*19 + tabA(rok)) % 30;
- e = (2*b + 4*c + 6*d + tabB(rok)) % 7;
- if ((d == 29 && e == 6) ||
- (d == 28 && e == 6))
- {
- d-=7;
- }
- return d+e;
- }
- /* pobierz dane od uzytkownika */
- int main()
- {
- int rok, data;
- cout<<"Podaj rok (33-2499)\n";
- cin>>rok;
- if ((rok < 33) || (rok > 2499))
- {
- cout<<"Podany rok nie jest w zakresie 33-2499.\n";
- return 0;
- }
- data = 22 + wielkanoc(rok);
- if (data > 31)
- {
- cout<<"Wielkanoc przypada "<< data%31 <<" kwietnia\n"<<endl;
- }
- else
- {
- cout<<"Wielkanoc przypada "<<data<<" marca\n"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement