Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct ASCIIword
- {
- int suma;
- char c[256];
- };
- ASCIIword asw[256];
- char v[256], *p, sep[]=" ,";
- int n, la, ok;
- int findlit(char sir[])
- {
- for(int i=0;sir[i]!='\0';++i)
- if(tolower(sir[i])>='a'&&tolower(sir[i])<='z')
- return 1;
- return 0;
- }
- int sumWord(char sir[])
- {
- int s=0;
- for(int i=0;sir[i]!='\0';++i)
- s+=(int)sir[i];
- return s;
- }
- int main()
- {
- cin.get(v,256);
- p=strtok(v,sep);
- while(p)
- {
- if(findlit(p))
- {
- ok=1;
- asw[la].suma=sumWord(p);
- strcpy(asw[la].c, p);
- la++;
- }
- p=strtok(NULL, sep);
- }
- if(!ok)
- cout<<"NU EXISTA";
- else
- {
- for(int i=0;i<la-1;++i)
- for(int j=i+1;j<la;++j)
- if(asw[i].suma>asw[j].suma)
- swap(asw[i], asw[j]);
- int i;
- for(i=0;i<la-1;++i)
- {
- if(asw[i].suma==asw[i+1].suma)
- {
- int j=i;
- cout<<asw[i].suma<<' ';
- while(asw[i].suma==asw[j].suma)
- cout<<asw[j].c<<' ',++j;
- cout<<'\n';
- i=j-1;
- }
- else
- cout<<asw[i].suma<<' '<<asw[i].c<<'\n';
- }
- if(i<la)
- cout<<asw[i].suma<<' '<<asw[i].c<<'\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment