当前位置:网站首页>刷题-洛谷-P1146 硬币翻转
刷题-洛谷-P1146 硬币翻转
2022-07-25 13:32:00 【宋向上_UP】
P1146 硬币翻转-C语言
1、问题

2、解题过程
(1)第一次 输出格式不对 忘了输出翻转次数了
结果:
代码:
//洛谷 P1146 硬币翻转
#include <stdio.h>
#define MAX 100 //表示硬币的个数
int main() {
int n;//不大于100的偶数
int s;//最少需要操作的次数
int coin[MAX] = {
1};//硬币状态 1表示反面朝上 0表示正面朝上
int i,j;
//int turn;//每次翻转的次数 n-1次
scanf("%d", &n);
for (i = 0; i < n; i++) {
//对硬币状态进行初始化
coin[i] = 0;//正面朝上
}
//限制n为偶数 减低了本题的难度
for (i = 0; i < n; i++) {
//n枚硬币最少需要翻转n次
for (j = 0; j < n; j++) {
if (j != i) {
//翻转
coin[j] = (coin[j] == 0) ? 1 : 0;//翻转
}
printf("%d", coin[j]);
}
if (i < n - 1) {
//最后一行不打印换行符
printf("\n");
}
}
return 0;
}
(2)第二次
结果:
代码:
//洛谷 P1146 硬币翻转
#include <stdio.h>
#define MAX 100 //表示硬币的个数
int main() {
int n;//不大于100的偶数
//int s;//最少需要操作的次数
int coin[MAX] = {
1};//硬币状态 1表示反面朝上 0表示正面朝上
int i,j;
//int turn;//每次翻转的次数 n-1次
scanf("%d", &n);
for (i = 0; i < n; i++) {
//对硬币状态进行初始化
coin[i] = 0;//正面朝上
}
//需要翻转n次
printf("%d\n", n);
//限制n为偶数 减低了本题的难度
for (i = 0; i < n; i++) {
//n枚硬币最少需要翻转n次
for (j = 0; j < n; j++) {
if (j != i) {
//翻转
coin[j] = (coin[j] == 0) ? 1 : 0;//翻转
}
printf("%d", coin[j]);
}
if (i < n - 1) {
//最后一行不打印换行符
printf("\n");
}
}
return 0;
}
边栏推荐
- Arrays常用方法
- 面试官问我:Mysql的存储引擎你了解多少?
- mujoco_ Py Chinese document
- Excel录制宏
- What is your revenue rank among global developers in 2022?
- 6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
- Concurrent programming - memory model JMM
- ES6数组去重 new Set()
- 若依如何实现用户免密登录配置方法?
- Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]
猜你喜欢

Excel record macro

In order to improve efficiency, there are various problems when using parallelstream

Convolutional neural network model -- vgg-16 network structure and code implementation

Design and principle of thread pool
![Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]](/img/70/2b5130be16d7699ef7db58d9065253.png)
Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]

2022全球开发者中,你的收入排多少?

Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets

Discussion on principle and application technology of MLIR

Mlx90640 infrared thermal imager temperature sensor module development notes (V)

程序员成长第二十七篇:如何评估需求优先级?
随机推荐
0715RHCSA
ES6数组去重 new Set()
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
领域驱动模型设计与微服务架构落地-模型设计
MLIR原理与应用技术杂谈
Hcip day 6 notes
0713RHCSA
Mlx90640 infrared thermal imager temperature sensor module development notes (V)
C # basic learning (XXIII)_ Forms and events
备战2022 CSP-J1 2022 CSP-S1 初赛 视频集
Hcip day 9 notes
好友让我看这段代码
Introduction to jupyter notebook
Docker learning - redis cluster -3 master and 3 slave - capacity expansion - capacity reduction building
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
mujoco_py中文文档
错误: 找不到或无法加载主类 xxxx
卷积神经网络模型之——LeNet网络结构与代码实现
电脑里一辈子都不想删的神仙软件
Shell common script: check whether a domain name and IP address are connected