Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, q, zmiana;
- int main()
- {
- cout << "Podaj ile jest czastek: ";
- cin >> n;
- cout << "\n";
- float tablica[n];
- cout << "Teraz podaj ich predkosci: ";
- for(int x=0;x<n;x++)
- {
- cin >> tablica[x];
- }
- //teraz sobie posortujemy
- do
- {
- zmiana =0;
- for(int x=0;x<n-1;x++)
- {
- if(tablica[x]>tablica[x+1])
- {
- int schowek;
- schowek = tablica[x+1];
- tablica[x+1]=tablica[x];
- tablica[x]=schowek;
- zmiana++;
- }
- }
- }
- while (zmiana != 0);
- cout << "\n" << "Podaj ile predkosci chcesz zbadac: ";
- cin >> q;
- float predkosci[q];
- float liczba[q];
- cout << "\n";
- cout << "Podaj te predkosci: ";
- for(int x;x<q;x++)
- {
- liczba[x]=0;
- }
- for(int x=0;x<q;x++)
- {
- cin >> predkosci[x];
- }
- cout << "\n";
- /*W tej petli prawdopodobnie jest blad*/
- /*->*/for(int x=0;x<q;x++)
- {
- int w=1;
- int m=1;
- int p=1;
- int k=q-1;
- int s=0;
- for(int wykonano=0;wykonano!=0;)
- {
- s=(p+k)/2;
- if(predkosci[x]>tablica[s])
- {
- p=s+1;
- }
- else if(predkosci[x]<tablica[s])
- {
- k=s-1;
- }
- else if(predkosci[x]==tablica[s])
- {
- for(int kolejne=0;kolejne!=0;)
- {
- liczba[x]++;
- if(tablica[s+w]==predkosci[x])
- {
- liczba[x]++;
- w++;
- }
- else if(tablica[s-m]==predkosci[x])
- {
- liczba[x]++;
- m++;
- }
- else
- {
- kolejne++;
- wykonano++;
- }
- }
- }
- else
- {
- wykonano++;
- }
- }
- }
- cout << "Te predkosci wystapily: ";
- for(int x=0;x<q;x++)
- {
- cout << liczba[x] << ", ";
- }
- cout << " razy.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement