Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- char s[300], a[300][300];
- int n,val[130],v[130];
- bool litera(char c)
- {
- if(c>='a'&& c<='z')return 1;
- if(c>='A'&& c<='Z')return 1;
- return 0;
- }
- bool test(char s[])
- {
- for(int i=0; s[i]; i++)
- if(litera(s[i])) return 1;
- return 0;
- }
- int Ascii(char s[])
- {
- int suma=0;
- for(int i=0; s[i]; i++) suma+=s[i];
- return suma;
- }
- void Prelucrare()
- {
- char *p,cuv[300];
- p=strtok(s," ");
- while(p)
- {
- strcpy(cuv,p);
- if(test(cuv))
- {
- strcpy(a[n],cuv);
- v[n]=val[n]=Ascii(cuv);
- n++;
- }
- p=strtok(NULL," ");
- }
- }
- void Sortare()
- {
- int ord=0, aux;
- while(ord==0)
- {
- ord=1;
- for(int i=0; i<n-1; i++)
- if(val[i]>val[i+1])
- {
- aux=val[i];
- val[i]=val[i+1];
- val[i+1]=aux;
- ord=0;
- }
- }
- }
- void Afisare()
- {
- cout<<val[0]<<' ';
- for(int j=0; j<n; j++)
- if(v[j]==val[0]) cout<<a[j]<<' ';
- cout<<'\n';
- for(int i=1; i<n; i++)
- if(val[i]!=val[i-1])
- {
- cout<< val[i]<<' ';
- for(int j=0; j<n; j++)
- if(v[j]==val[i]) cout<<a[j]<<' ';
- cout<<'\n';
- }
- }
- int main()
- {
- cin.getline(s,300);
- Prelucrare();
- if(n==0){cout<<"NU EXISTA"; return 0;}
- Sortare();
- Afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement