Advertisement
nicuvlad76

Untitled

Nov 24th, 2020
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. char s[300], a[300][300];
  5. int n,val[130],v[130];
  6.  
  7. bool litera(char c)
  8. {
  9.     if(c>='a'&& c<='z')return 1;
  10.     if(c>='A'&& c<='Z')return 1;
  11.     return 0;
  12. }
  13. bool test(char s[])
  14. {
  15.     for(int i=0; s[i]; i++)
  16.         if(litera(s[i])) return 1;
  17.     return 0;
  18. }
  19.  
  20. int Ascii(char s[])
  21. {
  22.     int suma=0;
  23.     for(int i=0; s[i]; i++)  suma+=s[i];
  24.     return suma;
  25. }
  26. void Prelucrare()
  27. {
  28.     char *p,cuv[300];
  29.     p=strtok(s," ");
  30.     while(p)
  31.     {
  32.         strcpy(cuv,p);
  33.         if(test(cuv))
  34.         {
  35.             strcpy(a[n],cuv);
  36.             v[n]=val[n]=Ascii(cuv);
  37.             n++;
  38.         }
  39.         p=strtok(NULL," ");
  40.     }
  41. }
  42. void Sortare()
  43. {
  44.     int ord=0, aux;
  45.     while(ord==0)
  46.     {
  47.         ord=1;
  48.         for(int i=0; i<n-1; i++)
  49.             if(val[i]>val[i+1])
  50.             {
  51.                 aux=val[i];
  52.                 val[i]=val[i+1];
  53.                 val[i+1]=aux;
  54.                 ord=0;
  55.             }
  56.     }
  57. }
  58. void Afisare()
  59. {
  60.     cout<<val[0]<<' ';
  61.     for(int j=0; j<n; j++)
  62.         if(v[j]==val[0]) cout<<a[j]<<' ';
  63.     cout<<'\n';
  64.     for(int i=1; i<n; i++)
  65.         if(val[i]!=val[i-1])
  66.         {
  67.             cout<< val[i]<<' ';
  68.             for(int j=0; j<n; j++)
  69.                 if(v[j]==val[i]) cout<<a[j]<<' ';
  70.             cout<<'\n';
  71.         }
  72. }
  73. int main()
  74. {
  75.     cin.getline(s,300);
  76.     Prelucrare();
  77.     if(n==0){cout<<"NU EXISTA"; return 0;}
  78.     Sortare();
  79.     Afisare();
  80.     return 0;
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement