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

In July 2022, domestic database memorabilia

Use "green computing" technology to promote sustainable development of computing power

《支付宝体验设计精髓》一书,跟测试相关性知识记录

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

从卖产品到卖“链路”:20条策略 解读直播带货迭代玩法

一些性能测试的要点
Force KouTi (5), the longest text string back

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

ERC20转账压缩

用“绿色计算“技术推动算力可持续发展
随机推荐
使用 Chrome 开发者工具的 lighthouse 功能分析 web 应用的性能问题
SIGIR 2022 | 邻域建模Graph-Masked Transformer,显著提高CTR预测性能
openharmony代码框架初识(2)
MySQL远程备份策略举例
awk statistical average max min
How to add custom syntax to MySQL?
正畸MIA微种植体支抗技术中国10周年交流会在沈举办
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
基于HDF的LED驱动程序开发(2)
【有奖征文】秋招特训,打造你的专属产品体验
In July 2022, domestic database memorabilia
视频目标检测
奥拉时钟芯片生成配置文件脚本
Dragoma (DMA) Metaverse System Development
Pedestrian fall detection experiment based on YOLOV5
SAP UI5 ensures that the control id is globally unique implementation method
蚂蚁集团时序数据库CeresDB正式开源
电脑一键重装系统内存完整性无法打开怎么办
VQ Realization of Wavelet Extraction Features
如何给MySQL添加自定义语法 ?