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

使用.NET简单实现一个Redis的高性能克隆版(二)

Video Object Detection

Pedestrian fall detection experiment based on YOLOV5

Defaced Fingerprint Recovery and Identification

PostgreSQL的 SPI_接口函数

Query the published version records of the APP Store

Quantitative trading robot system development

运维就业现状怎么样?技能要求高吗?

正则表达式未完

Use "green computing" technology to promote sustainable development of computing power
随机推荐
华为企业组网实例:VRRP+MSTP典型组网配置
小软件大作用 | 如何省时省力进行Gerber图层快速对比?
TritonVM——基于Recursive STARK的虚拟机
宏定义小方法
Ant Group's time series database CeresDB is officially open source
入门:人脸专集1 | 级联卷积神经网络用于人脸检测(文末福利)
目标检测的发展与现状
带你了解数据分布式存储原理
Initialization process of SAP UI5
nr part calculation
How to manually download and install SAP Fiori tools - Extension Pack for Visual Studio Code
电脑一键重装系统后连不上远程了?教你设置的方法
按需视觉识别:愿景和初步方案
How to add custom syntax to MySQL?
03 ts类型缩小,函数
The Development and Current Situation of Object Detection
蚂蚁集团时序数据库CeresDB正式开源
String中的hashcode缓存以及HashMap中String作key的好处
openharmony代码框架初识(2)
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误