13-14年华师上机题
2020-04-05 07:25
134 查看
- 编写一个程序,给出方程3x+2y-7z=5(其中,0≤x,y,z≤10),求满足方程的所有x,y和z,输出之
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; int main() { int x, y, z; for(x=0;x<=10;x++) for(y=0;y<=10;y++) for (z = 0; z <= 10; z++) { if ((3 * x + 2 * y - 7 * z) == 5) cout << "x=" << x << " y=" << y << " z=" <<z<< endl; } return 0; }
- 编写函数,实现如下功能,键盘输入一个整数,判断每一个数字(0-9)在这个整数中重复出现的次数,输出重复出现的数字及其出现次数。比如:输入3321181,则输出3出现了2次、1出现了3次;输入2186,则输出没有重复数字。
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; int main() { int n, a[10] = { 0 }; cin >> n; while (n) { a[n % 10]++; n = n / 10; } for (int i = 0; i < 10; i++) if (a[i] > 1) cout << i << " : " << a[i] << endl; return 0; }
- 类Person是一个描述人员信息的数据结构体,包括姓名(不定长)、性别、年龄。利用该结构体创建数组emp[5],调用自身的Get()方法可以输入人员的信息,并通过Show()方法显示输入的信息。请编写程序完成上述功能。
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; class Person{ private: string name; string sex; int age; public: void Get() { cout << "输入姓名 性别 年龄:" << endl; cin >> name >> sex >> age; } void Show() { cout << "输出姓名 性别 年龄:" << endl; cout << name <<" "<< sex <<" "<< age << endl; } }emp[5]; int main() { for (int i = 0; i < 5; i++) emp[i].Get(); for (int i = 0; i < 5; i++) emp[i].Show(); return 0; }
14年真题
4. 写一个求素数的算法。 20分
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; bool isprime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n%i == 0) return false; } return true; } int main() { int n; cin >> n; if (isprime(n)) cout << n << "是素数" << endl; else cout << n << "不是素数" << endl; return 0; }
- 在一个有序数列中插入一个数,使得数列依然有序,并且把最大的那个数剔除出队列 比如 3,5,9,12, 插入6,然后得 3,5,6,9 20分
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; int main() { int n, a[100]; cout << "输入数组个数:" << endl; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; cout << "变为有序序列:" << endl; sort(a, a + n); for (int i = 0; i < n; i++) cout << a[i] << ' '; cout << endl; cout << "输入要插入的数字:" << endl; cin >> a[n]; sort(a, a + n + 1); for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; return 0; }
- 输入一个任意数如451215,输出重复出现数字的次数,比如输出 5重复了2次 1重复了2次 20分
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; int main() { int n, cnt = 0, a[10] = { 0 }, i = 0; cin >> n; while (n) { a[n % 10] ++; n = n / 10; cnt++; } for (int i = 0; i < 10; i++) { if (a[i] > 1) cout << i << ": " << a[i] << endl; } return 0; }
- 写一个类,类里面包含了私有成员变量和方法,并且用该类里面的方法给私有成员变量赋值和输出 40分
#include<fstream> #include <iostream> #include<algorithm> #include<string> using namespace std; class Student { private: string num; string name; public: void setData() { cout << "输入学生 学号 姓名:" << endl; cin >> num >> name; } void getData() { cout << "输出学生 学号 姓名:" << endl; cout << num << " " << name << endl; } }; int main() { Student s; s.setData(); s.getData(); return 0; }
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- unknown error (Sqlite code 14): Could not open database, (OS error - 13:Permission denied)
- 启动3个线程打印递增的数字, 线程1先打印1,2,3,4,5, 然后是线程2打印6,7,8,9,10, 然后是线程3打印11,12,13,14,15. 接着再由线程1打印16,17,18,19,20.
- 北邮OJ-270. 众数-14计院上机(第二套)A
- 49骰子数独(13)115(14)
- 阅读<构建之法>13、14、15、16、17章
- fedora 13 14 硬盘安装 (windows xp下)
- python UnicodeEncodeError: 'ascii' codec can't encode characters in position 13-14: ordinal not in r
- 今日LeetCode--13 14
- 关于更新技术(About Update Techniques)-SM13 SM14 SM11
- java 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,
- LeetCode 13~14
- 回首13我们奋斗在14的路上
- MDT2010新功能(13/14)新TS模板/改进的数据库
- 1006_C/C++笔试题_15:16道c语言面试【13/14】
- 第一章13和14题
- 解锁VMware pro 14 Mac Os X 13 安装选项下载
- 北邮OJ-271. 旋转图像-14计院上机(第二套)B
- Fedora 12 13 14基础环境配置
- 北航复试上机14真题
- ERROR: Application requires API version 14. Device API version is 13 (Android 3.2)