【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;
 } 

结果

相关推荐
混分巨兽龙某某23 分钟前
基于Qt Creator的Serial Port串口调试助手项目(代码开源)
c++·qt creator·串口助手·serial port
小冯记录编程34 分钟前
C++指针陷阱:高效背后的致命危险
开发语言·c++·visual studio
C_Liu_1 小时前
C++:类和对象(下)
开发语言·c++
coderxiaohan1 小时前
【C++】类和对象1
java·开发语言·c++
阿昭L2 小时前
MFC仿真
c++·mfc
散1122 小时前
01数据结构-01背包问题
数据结构
消失的旧时光-19433 小时前
Kotlinx.serialization 使用讲解
android·数据结构·android jetpack
Gu_shiwww3 小时前
数据结构8——双向链表
c语言·数据结构·python·链表·小白初步
老赵的博客4 小时前
c++ unqiue指针
java·jvm·c++
苏小瀚4 小时前
[数据结构] 排序
数据结构