解题思路:
注意事项:下面的代码可以在我的VC上跑,不知道为啥平台上面跑不了,有无兄弟看一下啥原因
参考代码:
#include<stdio.h>
#include<malloc.h>
int main()
{
int n,i,j,cloth_nums,cloth_location,num = 0;
int *a1,*a2;
scanf("%d",&n);
a1 = (int*)malloc(sizeof(int)*(n+1));
for(i = 0;i<n+1;i++)
{
a1[i] = 0;
}
while(scanf("%d",&cloth_nums)!=EOF)
{
a2 = (int*)malloc(sizeof(int)*cloth_nums);
for(i = 0;i<cloth_nums;i++)
{
scanf("%d",&a2[i]);
}
scanf("%d",&cloth_location);
num = 0;
for(i = 0;i<cloth_nums;i++)
{
for(j=1;j<=a2[i];j++)
{
a1[num] = 1;
num++;
}
a1[num] = 2;
num++;
}
printf("%d\n",a1[cloth_location-1]);
for(i = 0;i<n+1;i++)
{
a1[i] = 0;
}
free(a2);
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:1206 |
川哥的吩咐 (C语言代码)浏览:875 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C++代码)(手动优化一下计算)浏览:1284 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:966 |
剪刀石头布 (C语言代码)浏览:753 |
输入输出格式练习 (C语言代码)浏览:850 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:519 |
C语言训练-字符串正反连接 (C语言代码)浏览:632 |
快速排序算法1浏览:884 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:459 |