2019:
1.确定整数是否是回文
https://blog.csdn.net/qq_42680327/article/details/81742609
#include <iostream>
//#include <cmath>
#include <cstring>
//#include<bits/stdc++.h>
using namespace std;
char h[10000000000000];
int n,i,j,a,b,c,d,e,yn;
int main() {
yn=0;
string w;
cin>>w;
strcpy(h,w.c_str());//字符串转字符数组,使用strcpy
// cout <<"a="<< d << endl;
i=0;
while(h[i]=='0'||h[i]=='1'||h[i]=='2'||h[i]=='3'||h[i]=='4'||h[i]=='5'||h[i]=='6'||h[i]=='7'||h[i]=='8'||h[i]=='9'){
i++;
b=i;
//cout <<"i="<< i << endl;
}
// b=sizeof(h);
//cout <<"b="<< b << endl;
for(j=0;j<b/2;j++){
if(h[j]!=h[b-j-1]){
yn++;
}
}
if(yn==0){
cout <<w<<" is ok"<< endl;
}else{
cout <<w<<" is not ok"<< endl;
}
return 0;
}
2.给一个只包含字符(){}[]的字符串string,判断字符串是否有效。(18分)
一个字符串有效即:
括号必须闭合,且括号类型必须相同。
括号闭合的顺序须正确。注意:空字符串也是有效的。
https://blog.csdn.net/lpl0129/article/details/96477994
3.给一个正整数n,找到总和为n的最小完全平方数的个数
添加链接描述
4.设计一个函数,实现判断一个数能否被3和5同时整除(若能整除返回1,不能整除返回0),在主函数中调用该函数,筛选出1-100中能被3和5同时整除的数。
#include <iostream>
#include <cmath>
using namespace std;
int h[10000];
int n,i,j,a,b,c,d,e;
int Shu(int);
int main() {
for(i=0;i<100;i++)
{
b=Shu(i);
if(b==1){
cout<<i<<endl;
}
}
return 0;
}
int Shu(int a){
if(a%3==0&&a%5==0){
return 1;
}else{
return 0;
}
}
5.设计一个汽车类vehicle,包含的数据成员有车轮个数wheels和车重weight。小车类car是它的派生类,其中包含载人数passenger_load。每个类都有相关数据的输出方法。在主程序中定义一个car类对象,对其车轮个数、车重、载人数进行设置并显示。(c++类)
#include <iostream>
//#include <cmath>
#include <cstring>
//#include<bits/stdc++.h>
using namespace std;
char h[10000000000000];
int n,i,j,a,b,c,d,e,yn;
class vehicle{
public:
int wheels;
int weight;
vehicle(double a,double b){
wheels=a;
weight=b;
}
void display(){
cout<<"wheels:"<<wheels<<endl;
cout<<"weight:"<<weight<<endl;
}
};
class car:public vehicle{
public:
int passenger_load;
car(double a,double b,double c):vehicle(a,b)
{
passenger_load=c;
}
void display(){
cout<<"passenger_load:"<< passenger_load<<endl;
vehicle::display();
}
};
int main() {
car car1(4,808.2,6);
car1.display();
return 0;
}
6.统计从键盘输入的50个实数中有多少个整数、负数、0
#include <iostream>
//#include <cmath>
#include <cstring>
//#include<bits/stdc++.h>
using namespace std;
char h[10000000000000];
int n,i,j,a,b,c,d,e,yn;
int main() {
a=0;b=0;c=0;
while(cin >> n)
{
if(n>0){
a++;
}else if(n==0){
b++;
}else{
c++;
}
}
cout << "the number for 0+:"<<a<< endl;
cout << "the number for 0: "<<b<< endl;
cout << "the number for 0-:"<<c<< endl;
return 0;
}
2018:
1.一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下,编写一程序求它在第10次落地时,共经过多少米?第10次反弹多高? (15分)
#include <iostream>
using namespace std;
float h=100;
float n[10];
float sum=100;
int main() {
int i;
for(i=10;i>0;i--){
h=h/2;
n[i]=h;
cout <<n[i]<< endl;
sum=sum+2*n[i];
}
sum=sum-n[1]*2;
cout <<"总共经过的路径为"<<sum<< endl;
cout <<"第10次反弹高度为"<<n[1]<< endl;
return 0;
}
2.编写程序求一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?编写程序输出结果。(15分)
#include <iostream>
#include <cmath>
using namespace std;
int n;
int main() {
int a,b;
for(n=0;n<10000;n++){
a=sqrt( n+168);
b=sqrt(n+100+168);
if(a*a==n+100&&b*b==n+268){
cout <<n<< endl;
}
}
return 0;
}
3.编写程序打印杨辉三角(10行)
#include <iostream>
#include <cstring>
using namespace std;
char h[10000000000000];
int n,i,j,a,b,c,d,e,yn;
int aa[10][10];
int main() {
for(i=0;i<10;i++){
for(j=0;j<10;j++){
if(i==j||i==0){
aa[i][j]=1;
}else{
aa[i][j]=aa[i-1][j]+aa[i-1][j+1];
}
}
}
for(j=0;j<10;j++){
for(i=0;i<10;i++){
if(i<=j){
cout<<aa[i][j]<<" ";
if(i==j){
cout<<""<<endl;
}
}
}
}
}
4.取任意个4位数(4个数字均为同一个数的除外).将该数的4个数字重新组合,形成可能的最大数和可能的最小数,再将两者之间的差求出来:对此差值重复同样过程,最后你总是能到达卡普雷卡尔黑洞。编写一个程序求这个黑洞值。(20分)(排序)
https://blog.csdn.net/u014689802/article/details/52092162
5.编写一程序,计算二叉树的最大宽度(二叉树所有层中结点个数的最大值)
https://blog.csdn.net/sinat_20177327/article/details/78289905
6.编写一程序,从数塔的顶层出发,在买一个结点可以选择向左或者向右走,一直走到最底层,要求找到一条路就,使得路径上的数值和最大(动态规划)
https://blog.csdn.net/u013709443/article/details/81212915
7.采用邻接表存储结构,编写一个算法,判别无向图中任意给定的两个顶点之间是否存在一条长度为为 k的简单路径。(20分)
https://blog.csdn.net/weixin_43982354/article/details/85706572
8.李明毕业后从事船运规划工作,有一货轮的最大载重量为M吨,有N件货物供选择装船,每件货物的重量和价值是不同的。李明的任务是从N件货物中挑选若干件上船,在满足货物总重量小于等于M的前提下,编写一程序使运走的货物的总价值最大。(20 分)(贪心,0-1背包)
https://blog.csdn.net/jason_9527/article/details/70231893
2017
1、使用getchar()和putchar()函数:从键盘输入一字符串,然后输出该字符串。(15分)(文件流)
#include <iostream>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
char h[10000000000000];
int n,i,j,a,b,c,d,e;
int aa[10][10];
int main() {
char ch;
while ((ch=getchar())&&c!='\n')
putchar(ch); //putchar()用来显示参数所表示字符
return 0;
}
2、4名专家对4款赛车进行评价.
A说:2号赛车是最好的。
B说:4号赛车是最好的。
C 说3賽车不是最好的。
D说: B说错了。
事实上只有一款赛车是最好的且名专家说对了。请编程输出最佳的车号。(15 分)
#include <iostream>
#include <cmath>
using namespace std;
int best,i,sum;
int main() {
for(i=1;i<5;i++){
best=i;
sum=(best==2)+(best==4)+(best!=3)+(best!=4);
//cout<<"i="<<i<<" "<<"sum="<<sum<<endl;
if(sum==1)
{
cout<<"最佳车号为:"<<i<<endl;
}
}
return 0;
}
3、输入个正整数n (设n≥2),判断是否为素数,若是则输心“Yes”,否则输出“No”。(20 分)
#include <iostream>
#include <cmath>
using namespace std;
int n,i,sum;
int main() {
cout<<"请输入大于等于2的整数"<<endl;
cin>>n;
sum=0;
for(i=1;i<n+1;i++){
if(n%i==0){
sum++;
}
}
if(sum==2){
cout<<n<<"为素数"<<endl;
}else{
cout<<n<<"为非素数"<<endl;
}
return 0;
}
4.同2015 4
5.与3类似
6.n盏灯从1到n按顺序依次编号,有n个人也从1到n按顺序依次编号,第一个人(I号)将灯全部关闭,第二个人(2号)将凡是2和2的倍数号的灯打开,第三个人(3号)将凡是3和3的倍数号的灯做相反处理(即该灯如为打开的,将它关闭;如为关闭的,将它打开)。以后的人都和3号一样,将凡是与自己相同编号的灯和是自己编号倍数的灯做相反处理。n(1≤n≤1000)从键盘输入,请问:当第n个人操作之后,哪盏灯是关闭的,输出其编号。
https://blog.csdn.net/weixin_42128813/article/details/81215895
7.请实现一个函数,将一个字符串中的空格替换成“%20”例如:字符串为We Are One经过替换之后的字符串为We20%Are20%One(20分)(遍历)
https://blog.csdn.net/wanglelelihuanhuan/article/details/51648588
8、写一个函数,查找链表中具有某特定学号的学生的结点信息非删除它,假设链表头指针用head表示。(20)(链表)
http://www.wb86.com/cjia/post/cjia_7.8.html
2016:
一.编写程序,输出乘法口诀表
#include <iostream>
#include <cmath>
using namespace std;
int h[1000];
int n,i,j,a,b;
int main() {
for(i=1;i<10;i++)
{ h[i]=1;
for(j=1;j<10;j++){
a=i*j;
cout<<i<<"*"<<j<<"="<<a<<"\n"<<endl;
}
}
return 0;
}
2.输入一行字符,分别统计出其中的英文字母、空格、数字和其他字符的个数
#include <iostream>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
int h[100];
int i,j,a,b,c,d,e,maxx;
int aa[10][10];
char n;
int main() {
cout<<"please write a line of letter"<<endl;
a=0;b=0;c=0;d=0;
while(cin>>n){
if(n>='0'&&n<='9'){
a++;
}else if((n>='a'&&c<='z')||(n>='A'&&c<='Z')){
b++;
}else if(n=' '){
c++;
}else{
d++;
}
cout<<"number:"<<n<<endl;
}
cout<<"number:"<a<a<<endl;
cout<<"letter"<<b<<endl;
cout<<"null"<<c<<endl;
cout<<"other"<<d<<endl;
return 0;
}
3.找出由7、8、9三个数字组成的三位数中,有多少个不重复的数字。如789
#include <iostream>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
int h[100];
int per[5];
int i,j,a,b,c,d,e,maxx,A,B,C,D,E,pa,pb,pc,pd,pe;
int aa[10][10];
char n;
int main() {
maxx=0;
for(i=7;i<10;i++){
per[0]=i;
for(j=7;j<10;j++){
if(j!=i){
per[1]=j;
for(a=7;a<9;a++){
if(a!=i&&a!=j){
per[2]=a;
for(b=1;b<6;b++){
if(b!=i&&b!=j&&b!=a){
maxx++;
cout<<per[0]<<per[1]<<per[2]<<endl;
}
}
}
}
}
}
}
cout<<"all:"<<maxx<<endl;
return 0;
}
4.校田径运动会上A、B、C、D、E5人分获百米、四百米行跳高、跳远和三级跳冠军。
观众甲说:B获三级跳冠军,D获跳高冠军
观众乙说: A获百米冠军,E获跳高冠军
观众丙说: C获跳远冠军,D获四百米
冠军观众丁说: B获跳高冠军,E获三级跳冠军
实际情况是每人说对一句,说错一句。请编程求出哪项冠军。(I5分)
#include <iostream>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
int h[100];
int per[5];
int i,j,a,b,c,d,e,maxx,A,B,C,D,E,pa,pb,pc,pd,pe;
int aa[10][10];
char n;
int main() {
for(i=1;i<6;i++){
per[0]=i;
for(j=1;j<6;j++){
if(j!=i){
per[1]=j;
for(a=1;a<6;a++){
if(a!=i&&a!=j){
per[2]=a;
for(b=1;b<6;b++){
if(b!=i&&b!=j&&b!=a){
per[3]=b;
for(c=1;c<6;c++){
if(c!=i&&c!=j&&c!=a&&c!=b){
per[4]=c;
pa=(per[1]==5)+(per[3]==3);
pb=(per[0]==1)+(per[4]==3);
pc=(per[2]==4)+(per[3]==2);
pd=(per[1]==3)+(per[4]==5);
if(pa==1&&pb==1&&pc==1&&pd==1){
for(d=0;d<5;d++){
if(per[d]==1){
cout<<"100 no.1 is "<<per[d]<<endl;
}
if(per[d]==2){
cout<<"400 no.1 is "<<per[d]<<endl;
}
if(per[d]==3){
cout<<"jump high no.1 is "<<per[d]<<endl;
}
if(per[d]==4){
cout<<"jump away no.1 is "<<per[d]<<endl;
}
if(per[d]==5){
cout<<"jump*3 no.1 is "<<per[d]<<endl;
}
}
cout<<"A="<<A<<" B="<<B<<" C="<<C<<" D="<<D<<" E="<<E<<endl;
}
}
}
}
}
}
}
}
}
}
/* cout<<"please write a line of letter"<<endl;
a=0;b=0;c=0;d=0;
while(cin>>n){
if(n>='0'&&n<='9'){
a++;
}else if((n>='a'&&c<='z')||(n>='A'&&c<='Z')){
b++;
}else if(n=' '){
c++;
}else{
d++;
}
cout<<"number:"<<n<<endl;
}
cout<<"number:"<<a<<endl;
cout<<"letter"<<b<<endl;
cout<<"null"<<c<<endl;
cout<<"other"<<d<<endl;
*/
return 0;
}
5.编写程序,输出菱形图案
https://blog.csdn.net/u013732401/article/details/63740702
#include <iostream>
#include <cstring>
using namespace std;
char h[10000000000000];
int n,i,j,a,b,c,d,e,yn;
int aa[10][10];
int main() {
for(a=1;a<10;a++){
for(i=1;i<=10-a;i++){
cout<<" ";
}
for(j=1;j<2*a;j++){
cout<<"*";
}
for(n=1;n<=10-a;n++){
cout<<" ";
}
cout<<" "<<endl;//转行
}
for(a=1;a<10;a++){
for(i=1;i<=a;i++){
cout<<" ";
}
for(j=1;j<2*(10-a);j++){
cout<<"*";
}
for(n=1;n<=a;n++){
cout<<" ";
}
cout<<" "<<endl;//转行
}
}
6.鸡翁一知情五,鸡母一值钱三,雏鸡三值钱一,百钱买百鸡,问公鸡,母鸡,雏鸡各多少?
#include <iostream>
#include <cmath>
using namespace std;
int h[1000];
int n,i,j,a,b,c,d,e;
int main() {
for(i=0;i<100;i++)
{
for(j=0;j<100;j++){
for(a=0;a<100;a++){
if((i*15+j*9+a*1)==300)
{
cout<<"公鸡:"<<i<<"母鸡:"<<j<<"雏鸡:"<<a<<endl;
}
}
}
}
return 0;
}
7.相传在古代印度的Bramah庙中,有位僧人整天把三根柱子上的金盘倒来倒去,他想把64个一个比一个小的金盘从一根柱子上移到另一个柱子上,移动过程遵守下述规则,每次只允许移动一只盘, 且大盘不得摞在小盘上。编写一个移动金盘的递归程序,移动3个金盘,借助另一个柱子,根据以上规则把三个金盘从一个柱子移动到另一个柱子。(20 分)
https://blog.csdn.net/xcbeyond/article/details/6843752
8.编写一个排序程序,要求使用插入排序算法。(20分)
http://c.biancheng.net/view/196.html
9.中秋佳节,有贵宾来到草原,主人要从羊群中选一只肥羊宴请宾客,当然要选最肥的,编写一个程序找出最终结果。(20 分)
#include <iostream>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
int h[100];
int n,i,j,a,b,c,d,e,maxx;
int aa[10][10];
int main() {
cout<<"please write all sheeps' weight"<<endl;
maxx=0;
while(cin>>n){
if(n>maxx){
maxx=n;
}
}
cout<<maxx<<endl;
return 0;
}
2015
1.在一个字符串中找出元音字母a,e, i, o, u出现的次数。
输入一行字符串(字符串中可能有空格,请用gets(s)方法把一行字符串输入到字符数组s中),字符串长度小于80个字符。
输出一行依次输出a,e, i, o,u在输入字符串中出现的次数,整数之间用空格分隔。
例如, 输入: If so, you already have a Google Account. You can sign in onthe right.
输出:5 4 3 7 3
#include <iostream>
using namespace std;
char words[80];
int main()
{
int i,j,h,d,p,k;
j=0;h=0;d=0;p=0;k=0;
cin.getline(words,80);
for(i=0;i<80;i++)
{
if(words[i]=='a')
j++;
if(words[i]=='e')
h++;
if(words[i]=='i')
d++;
if(words[i]=='o')
p++;
if(words[i]=='u')
k++;
}
cout << j<<" "<<h<<" "<<d<<" "<<p<<" "<<k<<endl;
return 0;
}
2.给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。输入数据包含多组测试实例,每组测试实例包含一行, 由两个整数m和n组成。
对于每组输入数据,输出一行,应包括两个整数x和y分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。你可以认为32位整数足以保存结果。(20分)
例如,输入:1 3
2 5
输出:4 28
20 152
#include <iostream>
using namespace std;
int main() {
int n,j;
while(cin >> n >> j)
{
int k=n%2;
int w=j%2;
if (k==0){
n=n*n;
}else{
n=n*n*n;
}
if (w==0){
j=j*j;
}else{
j=j*j*j;
}
cout << n << " " << j << endl;
}
3.二叉树结点定义如下:
typedef struct node
{int data;
struct node *lchild ,*rchild;
}bitree;
bitree *root;
请写出以root为根结点的二叉树的中序遍历算法(代码实现)
https://blog.csdn.net/pdcxs007/article/details/13626955
4.猴子吃桃问题:小猴摘了很多桃子,第一天吃了一半又多吃一个,第二天又吃掉一半再多吃一个, 如此下去,到第十天恰好还剩一个桃子。问第一天小猴摘了多少桃子? (20分)
#include <iostream>
using namespace std;
int n=1;
int main() {
int i;
for(i=9;i>0;i--){
n=(n+1)*2;
}
cout <<n<< endl;
return 0;
}
2014:
1、给你n个整数,求他们时所有奇数的乘积。(20 分)
输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。输出每组数守的所有奇数的乘积,对于测试实例、输取一行。
例如,输入:3123
42345
输出: 3
15
http://www.mamicode.com/info-detail-434375.html
2.对于给定的一个字符串,统计其中数字字符出现的次数。(20分)
输入数据有多行,第一行是一个整数n,表示测试实例的个数。后面跟着n行,每行包括一个由字母和数字组成的字符串。
对于每个测试实例,输出该串中数值的个数,每个输出占一行。
例如,输入: 2
asdfasdf123123asdfasdf
asdfl111l1lasdfasdfasdf
输出: 6
9
https://blog.csdn.net/gui951753/article/details/46993575
3.已知一个椭圆的长轴长为10,,短轴长为8,请用蒙特卡罗法计算这个椭圆的面积,并编程实现。(20 分)(蒙特卡罗法)
https://iask.sina.com.cn/b/iQWZK9Z0ItE3.html
4.输入m,n分别表示苹果数量与盘子的总数,要求输出苹果放在n个盘子的方法总数
例如:输入7 3
输出8
https://blog.csdn.net/qq_43227036/article/details/89932208
https://blog.csdn.net/QuitePig/article/details/8049442