程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#pragma pack (1)
typedef struct Load
{
unsigned n;
unsigned char m;
}Load;
#pragma pop
Load* init( unsigned );
void fun( unsigned ,char );
int main( void )
{
unsigned t;
Load* load;
unsigned i;
if ((scanf("%u",&t))!=1)
return 1;
if (t==0)
return 0;
load=init(t--);
for (i=0;i!=t;++i)
{
fun(load[i].n,( char )load[i].m);
puts("");
}
fun(load[i].n,( char )load[i].m);
free(load);
return 0;
}
Load* init( unsigned t )
{
unsigned i;
Load* load=( Load* )malloc(t*sizeof ( Load ));
assert(load);
unsigned char* s=( unsigned char* )malloc(sizeof ( s ));
assert(s);
for (i=0;i!=t;load[i++].m=*s)
{
if ( (scanf("%u%hhu",&load[i].n,&load[i].m))!=2&&load[i].m>9)
exit(EXIT_FAILURE);
sprintf(s,"%hhu",load[i].m);
}
free(s);
return load;
}
void fun( unsigned n,char m )
{
char* p=malloc(n*sizeof ( m )+sizeof ( char ));
assert(p);
memset(p,m,n*sizeof ( m ));
p[n]='\0';
while (n--)
puts(p);
free(p);
}