【CSP CCF记录】202209-1 如此编码

题目

过程

C++中"/"的使用

当a和被b均为int, long, char这样的整数类型,此时除法运算的结果为所得商的整数部分,例如:180/100,结果为1;

cpp 复制代码
	int a = 180;
	int b = a / 100;
	cout << b << endl;
	
    #结果为1

当a和b中有一个或两个都是小数(float,double)型的数,其商的结果为实际结果。例如:180.0/100,结果为1.8;

cpp 复制代码
	float a = 180.0;
	float b = a / 100;
	cout << b << endl;
	
    #结果为1.8

代码

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=30;
int a[N],c[N],b[N];
int main()
{
	cin>>n>>m;
	c[0]=1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		c[i]=c[i-1]*a[i];
	}

	for(int i=n;i>=1;i--)
	{
		int x=m/c[i-1];
		b[i]=x;
		m=m%c[i-1];
	}
	for(int i=1;i<=n;i++)
	{
		cout<<b[i]<<" ";
	}
	return 0;
 } 

结果

相关推荐
blasit2 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_3 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星3 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛5 天前
delete又未完全delete
c++
端平入洛6 天前
auto有时不auto
c++
琢磨先生David7 天前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
哇哈哈20217 天前
信号量和信号
linux·c++
多恩Stone7 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马7 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
qq_454245037 天前
基于组件与行为的树状节点系统
数据结构·c#