a53

ASCIIComp

a53
Jan 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct ASCIIword
  4. {
  5. int suma;
  6. char c[256];
  7. };
  8. ASCIIword asw[256];
  9. char v[256], *p, sep[]=" ,";
  10. int n, la, ok;
  11.  
  12. int findlit(char sir[])
  13. {
  14. for(int i=0;sir[i]!='\0';++i)
  15. if(tolower(sir[i])>='a'&&tolower(sir[i])<='z')
  16. return 1;
  17. return 0;
  18. }
  19.  
  20. int sumWord(char sir[])
  21. {
  22. int s=0;
  23. for(int i=0;sir[i]!='\0';++i)
  24. s+=(int)sir[i];
  25. return s;
  26. }
  27.  
  28. int main()
  29. {
  30. cin.get(v,256);
  31. p=strtok(v,sep);
  32. while(p)
  33. {
  34. if(findlit(p))
  35. {
  36. ok=1;
  37. asw[la].suma=sumWord(p);
  38. strcpy(asw[la].c, p);
  39. la++;
  40. }
  41. p=strtok(NULL, sep);
  42. }
  43. if(!ok)
  44. cout<<"NU EXISTA";
  45. else
  46. {
  47. for(int i=0;i<la-1;++i)
  48. for(int j=i+1;j<la;++j)
  49. if(asw[i].suma>asw[j].suma)
  50. swap(asw[i], asw[j]);
  51. int i;
  52. for(i=0;i<la-1;++i)
  53. {
  54. if(asw[i].suma==asw[i+1].suma)
  55. {
  56. int j=i;
  57. cout<<asw[i].suma<<' ';
  58. while(asw[i].suma==asw[j].suma)
  59. cout<<asw[j].c<<' ',++j;
  60. cout<<'\n';
  61. i=j-1;
  62. }
  63. else
  64. cout<<asw[i].suma<<' '<<asw[i].c<<'\n';
  65. }
  66. if(i<la)
  67. cout<<asw[i].suma<<' '<<asw[i].c<<'\n';
  68. }
  69. return 0;
  70. }
Add Comment
Please, Sign In to add comment