Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- char v[100][30];
- int n;// n este numarul de cuvinte
- void cauta(char *p)
- {
- int i;
- for(i=0;i<n;i++)
- if(strcmp(v[i],p)==0)
- return ;
- strcpy(v[n],p);
- n++;
- }
- int main()
- {
- char s1[256],s[256],*p;
- int i,ok;
- cin.getline(s,256);
- cin.getline(s1,256);
- for(i=0;i<strlen(s);i++)
- if(s[i]>='A' && s[i]<='Z')
- s[i]+=32;
- for(i=0;i<strlen(s1);i++)
- if(s1[i]>='A' && s1[i]<='Z')
- s1[i]+=32;
- p=strtok(s," ");
- while(p)
- {
- if(strstr(s1,p))
- cauta(p);
- p=strtok(NULL," ");
- }
- do
- {
- ok=1;
- for(i=0;i<n-1;i++)
- if(strcmp(v[i],v[i+1])>0)
- {
- swap(v[i],v[i+1]);
- ok=0;
- }
- }
- while(ok==0);
- for(i=0;i<n;i++)
- cout<<v[i]<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement