Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID : bristy11
- LANG : C++
- TASK : calfflac
- */
- //Bristy Sikder Loves U
- # include <iostream>
- # include <stdio.h>
- # include <map>
- # include <cstring>
- # include <vector>
- using namespace std;
- int main()
- {
- //data structures
- int a,b,c,size,alph,check;
- char line[40000]; // the main string
- char str[85];
- char smlet[]={"abcdefghijklmnopqrstuvwxyz"};
- char caplet[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
- vector <char> pal;
- map<int,int>tag;
- freopen("calfflac.in","r",stdin);
- freopen("calfflac.out","w",stdout);
- //input
- size=0;
- while (gets(str)!=NULL){
- int k;
- k=strlen(str);
- for(b=0;b<k;b++) line[size+b]=str[b];
- line[size+k]=1;
- size+=k+1;
- //cout << line << "\n";
- }
- /*for(int i=0;i<size;i++)
- {
- if(line[i]==1)
- printf("\n");
- else
- printf("%c",line[i]);
- }*/
- // printf(":\n");
- //sorting out the letters
- alph=0;
- for(a=0;a<size;a++){
- for(b=0;b<strlen(smlet);b++){
- if(line[a]==smlet[b]) {
- pal.push_back(caplet[b]);
- tag[alph]=a;
- alph++;
- //cout << line[a];
- }
- }
- for(b=0;b<strlen(caplet);b++){
- if(line[a]==caplet[b]) {
- pal.push_back(caplet[b]);
- tag[alph]=a;
- alph++;
- //cout << line[a];
- }
- }
- }
- //for(a=0;a<alph;a++) cout << pal[a] << " " << a << " ";
- //cout << endl;
- //processing
- int finlen=0;
- int finbeg=0;
- int finend=0;
- for(a=0;a<alph-1;a++){
- for(b=min(a+1999,alph-1);b>=max(a+1,a+finlen);b--){ // b<=size-1; b>finlen;
- //palindrome check
- //cout << a << " " << b << endl;
- check=0;
- for(c=0;c<=(b-a)/2;c++){
- //cout << pal[a+c] << pal[b-c] << " " <<a+c<< " " << b-c << endl;
- if(pal[a+c]!=pal[b-c]) {
- check=1;
- break;
- }
- }
- if(check==1) continue;
- else {
- finlen=b-a+1;
- finbeg=tag[a];
- finend=tag[b];
- //cout << finlen << endl;
- //for(a=finbeg;a<=finend;a++) cout << line[a];
- //cout << endl;
- break;
- }
- }
- }
- //results
- cout << finlen << endl;
- for(a=finbeg;a<=finend;a++)
- {
- if(line[a]==1) printf("\n");
- else cout << line[a];
- }
- printf("\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment