Varianta 31 / Subiectul 2 / Problema 5 |
#include<fstream.h> #include<string.h> struct nod{char info[30]; nod *leg; }; nod *prim; void adaugf(nod *&prim,char x[30]) {nod *nou=new nod; strcpy(nou->info,x); nou->leg=prim; prim=nou; } void afis(nod *prim) {nod *p=prim; while(p) {cout<<p->info<<" "; p=p->leg; } cout<<endl; } void main() {int n; char s[30]; cin>>n; for(int i=1;i<=n;i++) { cin>>s; if(s[0]==s[strlen(s)-1]) adaugf(prim,s); } afis(prim); } |