stupid me anyway it still gives runtime error
Code: Select all
#include<algorithm>
#include<cstdio>
#include<list>
using namespace std;
FILE *in=stdin;//fopen("hands.in","r");
class node{public:
int i,c;
};
node arr[100009];
char cards[100009];
int hands[100009];
int cum[100009];
bool vis[55];
int n;
void err()
{
while(1)printf("%s\n",cards);
}
int tonum(char* c)
{
int a,b;
if(*c=='J') b=10;
else if(*c=='Q')b=11;
else if(*c=='K')b=12;
else if(*c=='A')b=0;
else if(*c=='1')b=9,c[1]=c[2];
else b=*c-'1';
if(c[1]=='C') a=0;
else if(c[1]=='D')a=1;
else if(c[1]=='H')a=2;
else a=3;
return a*13+b;
}
bool operator < (node a,node b)
{
return a.c<b.c;
}
bool cmp(char a,char b)
{
return b<a;
}
int main()
{
int i,j,k,t=0,ans=0,s,l;
char cstr[10];
cards[100008]=0;
while(1)
{
fscanf(in,"%d",&n);
ans=0;
if(n==0)return 0;
t=0;
l=0;
for(i=0;i<n;i++) //reading hands
{
fscanf(in,"%d",hands+i);
for(j=0;j<hands[i];j++)
{
fscanf(in,"%s",cstr);
cards[t++]=tonum(cstr);
}
}
for(i=0;i<n;i++)
arr[i].i=i,arr[i].c=hands[i],l=max(l,hands[i]); //storing in a array of class "node"
cum[0]=0;
for(i=1;i<n;i++) //bulding cummulative sum table
cum[i]=cum[i-1]+hands[i-1];
sort(arr,arr+n); //sorting hands accsendingly on number of cards
for(i=0;i<n;i++) //sorting each hand
sort(cards+cum[i],cards+cum[i]+hands[i],cmp);
s=0;
for(i=0;i<l;i++) //greedy algorithm to count nodes
{
memset(vis,0,sizeof(vis));
for(j=s;j<n;j++) //count how many different card in position i of each hand
{
if(!vis[cards[cum[arr[j].i]+i]])ans++,vis[cards[cum[arr[j].i]+i]]=1;
if(arr[j].c-1==i)
s++;
}
}
printf("%d\n",ans);
}
}
I know that u probably hates reading others code ,but would u plz help me to find what could cause runtime error