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

Tuesday, February 4, 2014

IITWPC4A-Maggu and Strings

Maggu and Strings

below given code is for iitwpc4a spoj or maggu and strings spoj.
actually code was given by dukkar.
#include <stdio.h>
#include <cstring>
using namespace std;
int main()
{
 int t,i,a,b;
 char s[100005];
 scanf("%d",&t);
 while(t--)
 {
  scanf("%s",s);
  long long len=strlen(s);
  s[len]='#';
  long long temp=len,count=0,k;
  char temp1;
  scanf("%d%d",&a,&b);
  if(a<b){
   temp1='a';
   k=b-a;
   for(i=0;i<=len;i++)
   {
    if(temp1==s[i])
     count++;
    else
    {
     temp+=(count/a)*k;
     count=0;
    }
   }
   printf("%lld %lld\n",len,temp);
  }
  else if(a>b)
  {
   temp1='a';
   k=a-b;
   for(i=0;i<=len;i++)
   {
    if(temp1==s[i])
     count++;
    else
    {
     temp-=(count/a)*k;
     count=0;
    }
   }
   printf("%lld %lld\n",temp,len);
  }
  else
   printf("%lld %lld\n",len,len);
}
return 0;
}

No comments:

Post a Comment

Your comment is valuable to us