当前位置:网站首页>刷题-洛谷-P1151 子数整数
刷题-洛谷-P1151 子数整数
2022-07-25 13:32:00 【宋向上_UP】
P1151 子数整数-C语言
1、题目

2、解题过程
(1)第一次 没有通过,超级离谱,居然是因为NO的O要小写
结果:
代码:
//洛谷 P1151 子数整数
#include <stdio.h>
#define MIN 10000//最小值
#define MAX 30000//最大值
int main() {
int k;//正整数 0<K<1000
int sub1,sub2,sub3;
int i;
int counter=0;//计数器 解决最后一行换行问题
int temp[MAX];//存放结果
scanf("%d", &k);
for (i = MIN; i <= MAX; i++) {
sub1 = i / 100;
if ((sub1 % k) != 0) {
continue;
}
sub2 = (i % 10000) / 10;
if ((sub2 % k) != 0) {
continue;
}
sub3 = i % 1000;
if ((sub3 % k) != 0) {
continue;
}
temp[counter] = i;
counter++;
/* if ((sub1 % k == 0) & (sub2 % k == 0) & (sub3 % k == 0)) { //printf("%d", i); temp[counter] = i; counter++; }*/
}
if (counter == 0) {
printf("NO");
return 0;
}
for (i = 0; i < counter; i++) {
printf("%d", temp[i]);
if (i < counter-1) {
printf("\n");
}
}
return 0;
}
(2)第二次
结果:
代码:
//洛谷 P1151 子数整数
#include <stdio.h>
#define MIN 10000//最小值
#define MAX 30000//最大值
int main() {
int k;//正整数 0<K<1000
int sub1,sub2,sub3;
int a, b, c, d, e;
int i;
int counter=0;//计数器
scanf("%d", &k);
for (i = MIN; i <= MAX; i++) {
sub1 = i / 100 ;
sub2 = (i % 10000) / 10 ;
sub3 = i % 1000 ;
if ((sub1%k == 0) & (sub2%k == 0) & (sub3%k == 0)) {
counter++;
printf("%d\n", i);
}
}
if (counter == 0) {
printf("No");
}
return 0;
}
边栏推荐
- 0720RHCSA
- [Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
- 0716RHCSA
- Azure Devops(十四) 使用Azure的私有Nuget仓库
- 安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
- 卷积神经网络模型之——LeNet网络结构与代码实现
- HTTP cache tongtianpian, there may be something you want
- 0713RHCSA
- What is your revenue rank among global developers in 2022?
- stable_ Baselines quick start
猜你喜欢

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

What is your revenue rank among global developers in 2022?

Uncaught SyntaxError: Octal literals are not allowed in strict mode.

【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)

Convolutional neural network model -- alexnet network structure and code implementation

【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020

Date and time function of MySQL function summary

MLIR原理与应用技术杂谈
HTTP cache tongtianpian, there may be something you want

好友让我看这段代码
随机推荐
ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组
The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio
mujoco+spinningup进行强化学习训练快速入门
Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]
QingChuang technology joined dragon lizard community to build a new ecosystem of intelligent operation and maintenance platform
Numpy简介和特点(一)
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
Concurrent programming - memory model JMM
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
[ai4code final chapter] alphacode: competition level code generation with alphacode (deepmind)
【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)
JS Array indexOf includes sort() 冒号排序 快速排序 去重和随机样本 random
0719RHCSA
电脑里一辈子都不想删的神仙软件
Gym安装、调用以及注册
MLIR原理与应用技术杂谈
Immortal software in the computer that I don't want to delete all my life
Leetcode 113. path sum II
Mlx90640 infrared thermal imager temperature sensor module development notes (V)
【GCN-RS】Region or Global? A Principle for Negative Sampling in Graph-based Recommendation (TKDE‘22)