Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- #define Nmax 51
- using namespace std;
- ifstream f("careu.in");
- ofstream g("careu.out");
- int F[26];
- bool palindrom(char s[],int L)
- {
- for(int i=0;i<L/2;++i)
- if(s[i]!=s[L-1-i])
- return false;
- return true;
- }
- int puncte(char s[])
- {
- int p=0,n=strlen(s);
- if(n%2)
- n=n/2+1;
- else
- n=n/2;
- for(int i=0;i<n;++i)
- if(F[s[i]-'A']==0)
- F[s[i]-'A']=1,p+=(int)s[i];
- return p;
- }
- int main()
- {
- int n;
- f>>n;
- char s[Nmax],a[Nmax][Nmax],b[Nmax*25][Nmax];
- for(int i=0;i<n;++i)
- {
- f.get();
- f.get(s,51);
- for(int j=0;j<n;++j)
- a[i][j]=s[j];
- }
- int c;
- f>>c;
- int j,N=0;
- unsigned L,Lmax=0;
- for(int i=0;i<n;++i)
- {
- j=0;
- while(j<n)
- {
- L=0;
- while(a[i][j]!='.'&&j<n)
- s[L++]=a[i][j],++j;
- s[L]='\0';
- if(L>1&&palindrom(s,L))
- {
- if(L>Lmax)
- Lmax=L;
- strcpy(b[N++],s);
- }
- ++j;
- }
- }
- for(int i=0;i<n;++i)
- {
- j=0;
- while(j<n)
- {
- L=0;
- while(a[j][i]!='.'&&j<n)
- s[L++]=a[j][i],++j;
- s[L]='\0';
- if(L>1&&palindrom(s,L))
- strcpy(b[N++],s);
- ++j;
- }
- }
- for(int i=0;i<N;++i) /// Sortez
- for(int j=i;j<N;++j)
- if(strcmp(b[i],b[j])==1)
- swap(b[i],b[j]);
- int k=0;
- if(strlen(b[0])==Lmax&&Lmax)
- strcpy(a[0],b[0]),++k;
- for(int i=1;i<N;++i)
- if(strlen(b[i])==Lmax&&strcmp(b[i],b[i-1])!=0)
- strcpy(a[k++],b[i]);
- N=k;
- if(c==1)
- {
- g<<N<<'\n';
- for(int i=0;i<N;++i)
- g<<a[i]<<'\n';
- }
- else
- {
- int punctaj=0;;
- for(int i=0;i<N;++i)
- punctaj+=puncte(a[i]);
- g<<punctaj<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement