Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Friday, March 28, 2014

ICPC12C-The Encrypted Password

The Encrypted Password

below given code is for icpc12c spoj or the encrypted password spoj.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <climits>
#include <ctime>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int cum[26];
int main()
{
 int t;
 scanf("%d ",&t);
 while(t--)
 {
  char s[100009],o[100009];
  scanf("%s",s);
  scanf("%s",o);
  int i=0,a[27],j,flag,k;
  for(i=0;i<26;i++)
   cum[i]=0,a[i]=0;
  i=0;
  while(o[i] != '\0')
  {
   j=o[i] - 97;
   a[j]++;
   i++;
  }
  int size=i;
  i=0;
  while(i<size)
  {
   k=s[i++] -97;
   cum[k]++;
  }
  if(size == strlen(s)){
   flag=1;
   for(i=0;i<26;i++)
    if(cum[i] != a[i])
    {
     flag=0;
     break;
    }
   if(flag)
    printf("YES\n");
   else
    printf("NO\n");
   continue;
  }
  i=size;
  while(s[i]!='\0')
  {
   flag=1;
   k=s[i] - 97;
   cum[k]++;
   k=s[i-size]-97;
   cum[k]--;
   for(j=0;j<26;j++)
    if(cum[j] != a[j])
    {
     flag=0;
     break;
    }
   if(flag)
    break;
   i++;
  }
  if(flag)
   printf("YES\n");
  else
   printf("NO\n");
 }
 return 0;
}

No comments:

Post a Comment

Your comment is valuable to us