当前位置:网站首页>刷题-洛谷-P1319 压缩技术
刷题-洛谷-P1319 压缩技术
2022-08-04 19:44:00 【宋向上_UP】
P1319 压缩技术-C语言
1、题目

2、求解过程
结果:
代码:
//洛谷 P1319 压缩技术
#include <stdio.h>
#define NUM 200
int main() {
int n;
int m;//表示输入了多少个数
int figure[NUM];
int i = 0;
int j;
int sum = 0;
int counter = 0;//计数器 每N个数打印一个换行
scanf("%d", &n);
/* for (i = 0; i < n; i++) { scanf_s("%d", &figure[i]); }*/
while (sum < (n * n)) {
scanf("%d", &figure[i]);
sum = sum + figure[i];
i++;
}
m = i;
for (i = 1; i <= m; i++) {
j = 1;
if (i % 2 == 1) {
while (j <= figure[i - 1]) {
printf("0");
counter++;
if (counter == (n * n)) {
//去除最后一个换行
break;
}
if (counter % n == 0) {
printf("\n");
}
j++;
}
}
else {
while (j <= figure[i - 1]) {
printf("1");
counter++;
if (counter == (n * n)) {
//去除最后一个换行
break;
}
if (counter % n == 0) {
printf("\n");
}
j++;
}
}
//printf("\n打印了%d次啦\n", i);
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
二叉树的遍历
seata源码解析:seata server各种消息处理流程
对比几类主流的跨端技术方案
PostgreSQL的 SPI_接口函数
SIGIR 2022 | 邻域建模Graph-Masked Transformer,显著提高CTR预测性能
Spark提交参数说明和常见优化
【最新资讯】2022下半年软考新增2个地区公布报名时间
TritonVM——基于Recursive STARK的虚拟机
哈佛架构 VS 冯·诺依曼架构
How to add custom syntax to MySQL?
华为企业组网实例:VRRP+MSTP典型组网配置
The book "The Essence of Alipay Experience Design", a record of knowledge related to testing
[Awards for Essays] Autumn recruitment special training to create your exclusive product experience
IIC驱动OLED
正畸MIA微种植体支抗技术中国10周年交流会在沈举办
MMDetection 使用示例:从入门到出门
编译optimize源码实现过程
[Latest Information] 2 new regions will announce the registration time for the soft exam in the second half of 2022
基于HDF的LED驱动程序开发(2)









