Code: Select all
1
1 9
1
2
3
4
5
6
7
8
9
10
Code: Select all
Size 1
9
1
2
3
4
5
6
7
8
9
10
Moderator: Board moderators
Code: Select all
1
1 9
1
2
3
4
5
6
7
8
9
10
Code: Select all
Size 1
9
1
2
3
4
5
6
7
8
9
10
I was getting WA.Because I was doing[cpp] scanf("%d", &n);
gets(tmp), gets(tmp);
for (NULL; n--; NULL)
{
gets(tmp);
c = sscanf(tmp, "%d%d", &a, &b);
t = 0;
for (NULL; gets(buf[t]) && buf[t][0]; ++t)
;
if (c == 0)
display(1, t);
else if (c == 1)
display(a, a);
else
display(a, b);
if (n)
printf("\n");
}[/cpp]
Code: Select all
scanf("%d",&n);
gets(tmp);
while(n--)
{
gets(tmp);
gets(tmp);
i=0;
while(gets(buf[i])&&buf[i])
i++;
if(str[0]=='*')
{s=1;e=i;}
else if(str[1]=='\0')
{s=atol(tmp);e=s;}
else
{ssacnf(tmp,"%d%d",&s,&e);}
if(flag)
printf("\n");
flag=1;
for(size=s;size<=e;size++)
{
display_output();
printf("\n");
}
}
Tested nearly all cases available. Plz help.a b means show all subset sizes from a to b, inclusive
Code: Select all
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
int m;
string names [ 12 ];
int cnt;
char query [ 63 ];
void process();
void backtrack( int stInd, int rem, string output );
int main()
{
char tLine [ 63 ];
cin >> m;
cin.ignore();
cin.ignore();
for ( int i = 0; i < m; i++ )
{
cnt = 0; // refresh
cin.getline( query, 63, '\n' );
cin.getline( tLine, 63, '\n' );
while ( tLine[ 0 ] != NULL )
{
names[ cnt++ ] = tLine;
cin.getline( tLine, 63, '\n' );
}
if ( i >= 1 )
{
cout << endl;
}
process();
}
return 0;
}
void process()
{
int st, end;
if ( query[ 0 ] == '*' )
{
st = 1;
end = cnt;
}
else
{
char * tokenPtr;
tokenPtr = strtok( query, " " );
st = atoi( tokenPtr );
tokenPtr = strtok( NULL, " " );
if ( tokenPtr == NULL )
{
end = st;
}
else
{
end = atoi( tokenPtr );
}
}
for ( int i = st; i <= end; i++ )
{
if ( i >= st + 1 )
{
cout << endl;
}
cout << "Size " << i << endl;
backtrack( 0, i, "" );
}
}
void backtrack( int stInd, int rem, string output )
{
string tOut;
for ( int i = stInd; i < cnt - (rem - 1); i++ )
{
tOut = output;
tOut += names[ i ];
if ( rem >= 2 )
{
tOut += ", ";
backtrack( i + 1, rem - 1, tOut );
}
else
{
cout << tOut << endl;
}
}
}
Code: Select all
3
2 3
Times
Herald-Tribune
Post
New Advocate
*
abc
def
1
pqm
Code: Select all
Size 2
Times, Herald-Tribune
Times, Post
Times, New Advocate
Herald-Tribune, Post
Herald-Tribune, New Advocate
Post, New Advocate
Size 3
Times, Herald-Tribune, Post
Times, Herald-Tribune, New Advocate
Times, Post, New Advocate
Herald-Tribune, Post, New Advocate
Size 1
abc
def
Size 2
abc, def
Size 1
pqm
Code: Select all
Acc....