编程题总结 --- 2018

news/2025/3/14 18:15:50/

(1)输入一串字符串,字符串以“#”结尾,判断输入的字符串中0至9的个数。

#include<iostream>using namespace std;int main(){int sum = 0;string s;while(cin >> s){if(s == "#") break;int n = s.size();for(int i = 0; i < n; i ++){if(s[i] >= '0' && s[i] <= '9') sum ++;}}cout<<sum;return 0;
}

在这里插入图片描述

(2)输入学生的姓名和成绩,按照学生成绩进行排序后输出,要求用稳定的排序,flag表示正序、逆序输出。

#include<iostream>using namespace std;
const int N = 1e5+10;struct Stu{string name;string id;int grade;
}stu[N];int n,flag;
int main(){cin >> n >> flag;for(int i = 0; i < n; i ++){cin >> stu[i].name >> stu[i].id >> stu[i].grade;}for(int i = n - 1; i > 0; i --){for(int j = 0; j < i; j ++){if(flag == 1)if(stu[j].grade > stu[j+1].grade) swap(stu[j],stu[j+1]);elseif(stu[j].grade < stu[j+1].grade) swap(stu[j],stu[j+1]);}}cout<<stu[0].name<<" "<<stu[0].id<<"\n";cout<<stu[n-1].name<<" "<<stu[n-1].id<<"\n";return 0;
}

(3)输入年月日,求这是当年第几天。

在这里插入图片描述

#include<iostream>using namespace std;
const int N = 1e5+10;int date;
int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
//1 3 5 7 8 10 12
//4 6 9 11 
//2
bool isleap(int n){if(n % 400 == 0 ) return true;if(n % 4 == 0 && n % 100 != 0) return true;return false;
}
int main(){cin >> date;int year = date/10000;date%=10000;int mon = date/100;int day = date%100;int ans = 0;for(int i = 1; i < mon; i ++){if(mon == 2)if(isleap(year)) ans += 1;ans += month[i];}ans += day;cout<<ans;return 0;
}

(3)输入年月日,变形题:求当年第几天是几月几号。

#include<iostream>using namespace std;
const int N = 1e5+10;int year,date;
int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
//1 3 5 7 8 10 12
//4 6 9 11 
//2
bool isleap(int n){if(n % 400 == 0 ) return true;if(n % 4 == 0 && n % 100 != 0) return true;return false;
}
int main(){cin >> year >> date;int mon = 0,day = 0;int cnt = 0;if(isleap(year))month[2] ++;for(int i = 1; i <= 12; i ++){for(int j = 1; j <= month[i]; j ++){cnt ++;if(cnt == date){mon = i;day = j;}}}   cout<<mon<<" "<<day;return 0;
}

(4)将m个相同的球全部放到n个相同的盒子里有多少种放法。(球本身视为相同)

待补


http://www.ppmy.cn/news/1167148.html

相关文章

PeopleCode中Date函数的用法

语法 Date(date_num) 描述 The Date function takes a number in the form YYYYMMDD and returns a corresponding Date value. If the date is invalid, Date displays an error message. Date函数输入是一个形如“YYYYMMDD”的数字&#xff0c;返回一个相应的Date类型的值…

C++ vector 的使用

CSDN的uu们&#xff0c;大家好。这里是C入门的第十七讲。 座右铭&#xff1a;前路坎坷&#xff0c;披荆斩棘&#xff0c;扶摇直上。 博客主页&#xff1a; 姬如祎 收录专栏&#xff1a;C专题 目录 1. 构造函数 1.1 vector(size_t n, const T& val T()) 1.2 vector…

Vue 3.0中Treeshaking特性是什么?

一、是什么 Tree shaking 是一种通过清除多余代码方式来优化项目打包体积的技术&#xff0c;专业术语叫 Dead code elimination 简单来讲&#xff0c;就是在保持代码运行结果不变的前提下&#xff0c;去除无用的代码 如果把代码打包比作制作蛋糕&#xff0c;传统的方式是把鸡…

Java RestTemplate使用TLS1.0(关闭SSL验证)

1. 问题 使用RestTemplate调用Http API时&#xff0c;服务器是TLS1.0&#xff0c;但是客户端Java默认禁止TLS1.0&#xff0c;会报错&#xff1a;org.springframework.web.client.ResourceAccessException: I/O error on POST request for “https://10.255.200.114/health”: …

MATLAB - excel 读取

matlab中excel 读取 1. 写入excel文件 - xlswrite2. 读取excel文件 - xlsread 1. 写入excel文件 - xlswrite xlswrite(filename,A,sheet,xlRange) % 写入字符串 % 注意事项&#xff1a;Str需要是Cell格式&#xff0c;否则一个字母占一格 % Str {‘abc’}&#xff1b; xlswr…

【进阶C语言】C语言文件操作

1. 为什么使用文件 2. 什么是文件 3. 文件的打开和关闭 4. 文件的顺序读写 5. 文件的随机读写 6. 文本文件和二进制文件 7. 文件读取结束的判定 8. 文件缓冲区 一、文件与文件的意义 1.文件的意义 文件的意义&#xff0c;无非就是为什么要使用文件&#xff1f; &#xff08;1&…

扩展某个Vue组件时会怎么做?

答题思路&#xff1a; 按照逻辑扩展和内容扩展来列举&#xff0c;逻辑扩展有&#xff1a;mixins、extends、composition api&#xff1b;内容扩展有slots&#xff1b; 分别说出他们使用方法、场景差异和问题。 作为扩展&#xff0c;还可以说说vue3中新引入的composition api…

接口收费背后的商业伦理

文/明道云创始人任向晖 周末去一家Shopping Mall&#xff0c;先到一个服装品牌店铺买一件秋季外套&#xff0c;结账时收银员说&#xff0c;帅哥&#xff0c;不好意思&#xff0c;衣服499&#xff0c;但是您还需要付五块钱商场管理费。我很惊讶&#xff0c;问为什么&#xff0c;…