- 博客(12)
- 收藏
- 关注
原创 C++中map知识
/删除区间的键及其值,first和last都是迭代器。If(A.find(1)==a.ends())返回一个迭代器,失败则返回的迭代器指向end。map,需要注意的是,若使用字符串到整型的映射,需要用string。构造迭代器:map ::iterator it;//删除it指向的键其对应的值。If(a.count(str))返回1,0。a.clear();
2023-08-03 09:49:11
70
1
原创 类的设计与运用:图书商店管理系统
1.6)编写一个公有成员函数模拟销售操作,用于减少该书籍的库存数量,该函数的参数是销售量,注意:销售量不能超过库存量,函数返回实际销售的数量。2.2)编写一个公有成员函数,为书店添加一个书籍信息(即Book对象),调用vector::push_back函数实现。2.3)编写一个公有成员函数,展示该书店中所有书籍信息,每一行展示一条书籍记录,并在最后另起一行展示书籍总数和总价。1.5)编写一个公有成员函数模拟入库操作,用于增加该书籍的库存数量,该函数的参数是入库量。1)编写一个表示书籍信息的类Book。
2022-11-17 22:27:06
193
原创 整数分解的方法
小节:先将mask成为与输入数相同的位数,以便取得最高位,再执行循环:1.先将数对mask除得下一位2.再将数对mask余所得赋值给x3.对mask位数调整使与新x位数一致循环条件:mask整数大于0#include<stdio.h>int main(){int x;scanf("%d",&x);int y=x;int mask=1;while(y>=10){mask*=10;y/=10;}//printf("%d",mask) ;while(
2021-10-10 16:30:35
113
原创 凑硬币(不打字了)
#include<stdio.h>int main(){int x,one,two,five;scanf("%d",&x);for(one=1;one<x*10;one++){for(two=1;two<x*5;two++){for(five=1;five<x*2;five++){if(one+two*2+five*5==x*10){printf("%d %d %d\n",one,two,five);goto out;}}}}out: .
2021-10-03 15:24:36
63
原创 打印100以内的素数
#include<stdio.h>int main(){ int x; int i; for (x = 1; x <= 100; x++) { int prime = 1; for (i = 2; i < x; i++) { if (x % i == 0){ prime = 0; break;}} if (prime == 1) { printf("%d ", x); }} return 0;}需要注意的是:每次应该完成pri.
2021-10-02 18:48:11
179
原创 简单的循环套循环
#include<stdio.h>int main(){ int x; for (x = 1; x <= 100; x++) { int prime = 1; int i; for (i = 2; i < x; i++) { if (x % i == 0){ prime = 0; break;}} if (prime == 1) { printf("%d\n", x); }} return 0;}
2021-10-02 17:05:27
240
原创 阶乘的好写法
#include<stdio.h>int main() { int x; scanf_s("%d", &x); int f=1; while (x > 0) { f = f * x; x = x - 1; } printf("%d", f); return 0;}
2021-09-29 22:54:02
90
原创 整数的逆序
#include <stdio.h>int main(){int x;int ret=0;int digit;printf("please write your number\n");scanf("%d",&x);while(x>0){digit=x%10;ret=ret*10+digit;x/=10;}printf("%d",ret);return 0;}
2021-09-29 22:15:23
64
原创 猜数游戏真好玩
#include<stdlib.h>#include<time.h>int main(){srand(time(0));int number=rand()%100+1;int count=0;int a=0;do{printf("请猜一下数\n");scanf("%d",&a);if (a>number){printf("你猜大了\n");count++;}if(a<number){printf("你猜小了\n");count++..
2021-09-29 20:55:41
73
原创 暑期自学·····先写一个小代码吧,某书上面的一个例子的模仿,使用了scanf函数,它是一种格式输出函数,今天初次认识!
#include <stdio.h>int main(){ float weight; float value; printf("are you worth your weight in your platinum?\n"); printf("let us check it out .\n"); scanf_s("%f", &weight); value = 1700.0 * weight * 14.5833; printf("your weight in plati.
2021-08-30 22:28:27
129
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人