当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
猜你喜欢

【ASP.NET Core】 中间件

华为企业组网实例:VRRP+MSTP典型组网配置

电脑一键重装系统内存完整性无法打开怎么办

"WAIC 2022 · hackers marathon" two ants wealth competition invited you to fight!

LED的C语言应用程序

图片延迟加载、预加载

ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators

【着色器实现Glitch单项故障闪烁效果(与Television效果不同)_Shader效果第十四篇】

如何推动乡村振兴的落地

红外图像滤波
随机推荐
Openharmony first experience (1)
Finger Vein Recognition-matlab
面试官:JVM运行时数据区包含哪几部分?作用是啥?
Kubernetes之list-watch机制
QT 小知识随记
性能测试流程
编译optimize源码实现过程
工业相机CCD与CMOS
Go学习笔记(篇一)配置Go开发环境
openharmony代码框架初识(2)
5 g NR notes
七夕福利!中奖名单:书籍免费送!
openharmony初体验(1)
MMDetection 使用示例:从入门到出门
Dragoma(DMA)元宇宙系统开发
How to monitor code cyclomatic complexity by refactoring indicators
awk 统计差值记录
If it is test axi dma catch a few words here
ERC20转账压缩
Use "green computing" technology to promote sustainable development of computing power