东华oj基础题135(1-102题)

东华oj基础题135

1 求长方形的面积和周长

在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{
	int a, b;
	cin >> a;
	cin >> b;
	cout << a * b<<" ";
	cout << 2 * (a + b) << endl;
	return 0;
}

2 数列和

在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{
	int a, i;
	int s = 0;
	cin >> a;
	for (i = 1; i <= a; i++) s += i;
	cout << s;
	return 0;
}

3 解方程

在这里插入图片描述

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
	int a, b;
	double s;
	cin >> a;
	cin >> b;
	s = (5 - 3 * b) / 2.0 / a;
	cout << fixed << setprecision(1) << s;
	return 0;
}

4 一个月的天数

在这里插入图片描述

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
	int a, b;
	int s;
	cin >> a;
	cin >> b;
	if (b != 2)
	{
		if (b % 2 == 1 && b <= 7) s = 31;
		else if (b % 2 == 1 && b > 7) s = 30;
		else if (b % 2 == 0 && b <= 7) s = 30;
		else s = 31;	
	}
	else
	{
		if (a % 4 == 0 && a % 100 != 0)s = 29;
		else if (a % 400 == 0)s = 29;
		else s = 28;
		
	}
	cout << s;

	return 0;
}

5 银行存款到期日

在这里插入图片描述

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
	int a, b,c,d;
	int s,t=0;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	s = b + d;
	while (s-12>0)
	{
		a++;
		s = s - 12;
	}
	if (s!= 2)
	{
		if (s % 2 == 1 && s <= 7) t = 31;
		else if (s % 2 == 1 && s > 7) t = 30;
		else if (s % 2 == 0 && s <= 7) t = 30;
		else s = 31;
	}else
	{
		if (a % 4 == 0 && a % 100 != 0)t = 29;
		else if (a % 400 == 0)t = 29;
		else  t = 28;

	}
	if (c > t)c = t;
	cout << a << " " << s << " " << c;
	return 0;
}

6 实数运算

在这里插入图片描述

#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
	double a, b;
	cin >> a;
	cin >> b;
	char c;
	cin >> c;
	if (b == 0) cout << "Wrong!";
	else
	{
		if (c=='+' ) cout << fixed << setprecision(1) <<a+b ;
		else if(c=='-') cout << fixed << setprecision(1) << a - b;
		else if (c == '*') cout << fixed << setprecision(1) << a * b;
		else if (c == '/') cout << fixed << setprecision(1) << a / b;
	}
	

	return 0;
}

7 解二次方程

-

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b,c;
	cin >> a;
	cin >> b;
	cin >> c;
	double d= b * b - 4.0* a * c;
	double x1, x2;
	if (d >=0)
	{
		d = sqrt(d); 
		x1 =( d - b)/2.0/a;
		x2 = ( - d - b ) / 2.0 / a;
		cout <<fixed <<setprecision(2) << x1 << " " << x2;
	}
	else cout << "Wrong!";

	return 0;
}

8 门票价格计算

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a; 
	double d;
	cin >> a;
	if (a <=20)d = a * 5.0;
	else if (a <= 40) d = a * 5.0 * 0.9;
	else if (a <= 80) d = a * 5.0 * 0.85;
	else if (a <= 120) d = a * 5.0 * 0.8;
	else  d = a * 5.0 * 0.7;
	cout << fixed<<setprecision(2) << d;
	

	return 0;
}

9 星期几问题

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin >> a;
	switch (a)
	{
	case 0:cout << "Sunday"; break;
	case 1:cout << "Monday"; break;
	case 2:cout << "Tuesday"; break;
	case 3:cout << "Wednesday"; break;
	case 4:cout << "Thursday"; break;
	case 5:cout << "Friday"; break;
	case 6:cout << "Saturday"; break;

	default:cout << "Wrong!";
		break;
	}


	return 0;
}

10 时间相加

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long ah,am,as,bh,bm,bs,ch,cm,cs;
	cin >> ah;
	cin >> am;
	cin >> as;
	cin >> bh;
	cin >> bm;
	cin >> bs;
	cs = as + bs;
	cm = am + bm;
	ch = ah + bh;
	if(cs - 60 >= 0) {
		cs -=60;
		cm++;
	}
	if (cm - 60 >=0) {
		cm -=60;
		ch++;
	}
	cout << ch << " " << cm << " " << cs;
	return 0;
}

11 成绩转换

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	if (t < 0 || t>100)cout << "Score is error!";
	else if (t < 60)cout << "E";
	else if (t < 70)cout << "D";
	else if (t < 80)cout << "C";
	else if (t < 90)cout << "B";
	else cout << "A";
	return 0;
}

12 求第几天

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,y,r,s=0;
	cin >> n;
	cin >> y;
	cin >> r;
	int i = 0;
	while (y-1>0)
	{
		i++;
		switch (i)
		{
		case 1:s += 31; y = y - 1; break;
		case 2:if((n%4==0&&n%100!=0)||n%400==0)s += 29; 
			else s += 28;
			 y = y - 1;
				break;
		case 3:s += 31; y = y - 1; break;
		case 4:s += 30; y = y - 1; break;
		case 5:s += 31; y = y - 1; break;
		case 6:s += 30; y = y - 1; break;
		case 7:s += 31; y = y - 1; break;
		case 8:s += 31; y = y - 1; break;
		case 9:s += 30; y = y - 1; break;
		case 10:s += 31; y = y - 1; break;
		case 11:s += 30; y = y - 1; break;
		case 12:s += 31; y = y - 1; break;
		}
	}
	s += r;
	cout << s;
	return 0;
}

13 求阶乘结果0的个数

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//暴力会错不知道为啥
	/*int i1,i2, s=0,s2=0;
	cin >> i1;
	cin >> i2;
	for (int j = 1; j <= i1; j++)
	{
		int t = j;
		while (t % 5 == 0)
		{
			s++;
			t /= 5;
		}
	}
	for (int p = 1; p <= i2; p++)
	{
		int q = p;
		while (q % 5 == 0)
		{
			s2++;
			q /= 5;
		}
	}
	cout << s << endl;
	cout << s2<< endl;*/
	int n;
	while (cin>>n)
	{
		int sum = 0;
		for (int i = 1; i <= n; i++)
		{
			int j = i;
			while (0 == j % 5)
			{
				sum++;            // 统计公约数5出现的频次
				j /= 5;
			}
		}
		printf("%d\n", sum);
		
	}
	
	return 0;
}

14 怪数

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n1;
	cin >> n1;
	for (int n = 6; n <=n1; n++)
	{
		int i = n / 2;
		int s = 1;
		for (int j = 2; j <= i; j++)
		{
			if (n % j == 0)s += j;
		}
		if (s == n)cout << s << endl;
	}
	return 0;
}

15 abc数字

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	while (cin >> a && cin >> b && cin >> c)
	{
		int count = 0;
		int s1 = a * 100 + b * 10 + c;
		int s2 = c * 100 + b * 10 + a;
		int s = s1 * s2;
		while (s)
		{
			if (s % 10 == a || s % 10 == b || s % 10 == c) count++;
			s /= 10;
		}
		cout << s1 * s2 << " " << count << endl;
	}
	return 0;
}

16 奇妙的比值

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double sum, b;
	while (cin >> n)
	{
		sum = 0;
		for (int a = 1; a <=n; a++)
		{
			if (n % a == 0)
			{
				sum += a;
				
			}
		}
		
		b = sum/ n;
		cout << fixed << setprecision(2) << b << endl;
		
	}
	return 0;
}

17 T的倍数N

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int sum, b;
	bool flag ;
	while (cin >> n)
	{
		sum = 0; flag = false;//flag表示是否找到
		for (int a = 7; a <= 1000000 && flag == false; a+=10)
		{
			
				int t = a , count = 0, b=t/10;//b为右移之后的数值
				while (t != 0)
				{
					t = t/ 10;
					count++;
				}
				sum = 7 * pow(10, count - 1) + b;//七移到首位
				if (n * a == sum)
				{
					cout << a << endl;
					flag = true;
				}	
		}
		if (flag == false) cout << "No" << endl;
	}
	return 0;
}

18 三角形

在这里插入图片描述

#include<iostream>
#include <iomanip>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	while (cin >> a&&cin>>b)
	{
		for (int i = 1; i <= b; i++)
		{
			for (int j = 1; j <i; j++)
			{
				if (a == 10)a = 1;
				cout << a++<<" ";
			}
			if (a == 10)a = 1;
			cout <<a++<<endl;
		}
		cout << endl;
	}
	return 0;
}

19 数字串处理

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int c[100], b, n, k, count, t, i;
	while (cin >> n) 
	{
		count = 1;
		for (i = 0; i < n; i++)
		{
			cin >> c[i];
		}
		k = c[0];
		t = 1;
		for (i = 1; i < n; i++) 
		{
			if (c[i] == c[i - 1]) t++;
			else
			{
				if (t > count) 
				{
					count = t;
					k= c[i-1];
					t = 1;
				}
				else {
					t = 1;
				}
			}
		}if (t > count) {
			count = t;
			k = c[i - 1];
		}
		cout << k << " " << count << endl;
	}
	return 0;
}

20 公式求解

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b,x,y;
	while (cin >> a && cin >> b)
	{
		if (a == 0 && b == 0) break;
		for (x = 1; x <= 100; x++)
		{
			for ( y = 1; y <= 100; y++)
			{
				if (a * a + x * x == b * b + y * y)
				{
					cout << x << " " << y << endl;
					break;
				}
			}
		}
		cout << endl;
	}
	
	return 0;
}

21 累加式

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	while (cin >> n)
	{
		if (n != 1)
		{
			for (i = 1; i <= n; i++)
			{
				cout << i << "+";
			}

			for (i = n - 1; i >= 1; i--)
			{
				if (i != 1) cout << i << "+";
				else cout << i << endl;

			}
		}
		else
		{
			cout << 1 << endl;;
		}		
	}
	return 0;
}

22 约瑟夫环2(难)

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	int a, m;//人质人数,间隔人数
	int start, last;//start从哪个人开始,last现有人数
	bool tag;//是否成功
	while (cin >> a) {
		tag = false;
		m = a + 1;//从第一个劫匪开始
		while (!tag) {//找到了{true}就停止
			tag = true;
			last = 2 * a;
			start = (m % last);
			if (start == 0) { start = last; }
			for (int i = 0; i < a; i++) {//循环 a 次
				if (start <= a) {//落在人质位,试下一个
					tag = false;
					break;
				}
				else {
					last--;//右端劫匪减一
					start--;//被干掉一个人,回到前一位
					start = (start + m) % last;
					if (start == 0) { start = last; }
				}
			}
			if (tag) {
				cout << m<< endl;;
			}
			m++;
		}
	}
}


23 整除的尾数

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t, i, a, b, tag = 0;

	while (cin >> t)//几组数据
	{
		i = 1;//第几组
		while (i <= t)
		{
			tag = 0;//是否第一次成功找到 控制格式
			cin >> a;
			cin >> b;
			for (int j = 1; j < 100; j++)
			{
				if ((a * 100 + j) % b == 0 && tag == 0) 
				{ cout << j;
					tag++; }
				else if ((a * 100 + j) % b == 0 && tag != 0)
				{
					cout << " " << j;
				}
			}
				cout << endl;
				i++;
		}
		
	}

	

	return 0;
}

24 回文质数

在这里插入图片描述

#include <stdio.h>
 
int fun1(int a)//判断是否为质数
{
	if(a<4)
		return 1;
	for(int i=2;i<sqrt(a);i++)
		if(a%i==0)
			return 0;
	return 1;
}
 
int fun2(int a)//判断是否为回文
{
	int record[6];
	int count=-1,i;
	if(a/10==0)
		return 1;
	while(a)
	{
		record[++count]=a%10;
		a/=10;
	}
	for(i=0;i<=count/2;i++)
		if( record[i] != record[count-i] )
			return 0;
	return 1;
}
 
int main()
{
	int a,b,i;
	scanf("%d %d",&a,&b);
	for(i=a;i<=b;i++)
	{
		if( fun2(i) )
		{
			if( fun1(i) )
				printf("%d\n",i);
		}
		else continue;
	}
	return 0;
} 

25 汽水瓶

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,count;
	while(cin >>n)
	{
		if (n == 0)break;
		count = 0;
		int t = n+1;
		while (t >= 3)
		{
			count++;
			t -= 2;
		}
		cout << count << endl;
		
	}
	return 0;
}

26 阶乘最后的非0位

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,sum;
	while(cin >>n)
	{
		sum = 1;
		for (int i = 1; i <= n; i++)
		{
			sum *= i;
			while (sum % 10 == 0)
				sum = sum / 10;
			sum = sum % 1000;
		}
		cout << sum % 10 << endl;
		
	}
	return 0;
}

27 算菜价

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
//因为只是数字相乘不需要用结构体
int main()
{
	int n, i;
	string name;
	double num, price, sum = 0.00;
	//输入有几个数据
	while (cin >> n)
	{
		for (int j = 1; j <= n; j++)
		{
			sum = 0.00;
			//输入有几行
			cin >> i;
			//输入单价和数量
			for (int t = 1; t <= i; t++)
			{
				cin >> name;
				cin >> num;
				cin >> price;
				sum += (num * price);
			}
			cout << fixed << setprecision(1) << sum<<endl;
		}
		
	}
	return 0;
}

28 水果价格

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;

int main()
{
	double aU = 1.5, oU = 1.4, bU = 1.48, pU = 1.08;
	int n;
	while (cin >> n) {
		double sumA = 0, sumO = 0, sumB = 0, sumP = 0, sumPrice = 0, sumWeight = 0;
		char specie;
		double weight;
		double weights[4] = { 0 };
		for (int i = 0; i < n; i++) {
			cin >> specie >> weight;
			switch (specie) {
			case 'a': sumA += weight * aU; weights[0] += weight; break;
			case 'o': sumO += weight * oU; weights[1] += weight; break;
			case 'b': sumB += weight * bU; weights[2] += weight; break;
			case 'p': sumP += weight * pU; weights[3] += weight; break;
			}
			sumPrice = sumA + sumO + sumB + sumP;
			sumWeight = weights[0] + weights[1] + weights[2] + weights[3];
		}
		cout<<"       apple  orange banana pineapple sum"<<endl;
		printf("price  %-7.2f%-7.2f%-7.2f%-10.2f%-7.2f\n", sumA, sumO, sumB, sumP, sumPrice);
		printf("weight %-7.2f%-7.2f%-7.2f%-10.2f%-7.2f\n", weights[0], weights[1], weights[2], weights[3], sumWeight);
		printf("\n");
	}
	return 0;
}

29 求奇数的乘积

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a;
	while (cin >> n)
	{
		int sum =1;
		for (int i = 1; i <= n; i++)
		{
			cin >> a;
			if (a % 2 == 1) sum *= a;
		}
		cout << sum << endl;
	}
	
	return 0;
}

30 求最晚和最早日期

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t, n, y, r;
	while (cin>>t)
	{
		int maxY = 0, maxN = 0, maxR = 0, minY = 13, minN = 2016, minR = 32;
		for (int i = 1; i <= t; i++)
		{
			cin >> n;
			cin >> y;
			cin >> r;
			if (n > maxN)
			{
				maxN = n;
				maxY = y;
				maxR = r;
			}
			if (n == maxN)
			{
				if (y > maxY)
				{
					maxN = n;
					maxY = y;
					maxR = r;
				}
				if (maxY == y)
				{
					if (r > maxR)
					{
						maxN = n;
						maxY = y;
						maxR = r;
					}
				}
			}
			if (n < minN)
			{
				minN = n;
				minY = y;
				minR = r;
			}
			if (n == minN)
			{
				if (y < minY)
				{
					minN = n;
					minY = y;
					minR = r;
				}
				if (minY == y)
				{
					if (r < minR)
					{
						minN = n;
						minY = y;
						minR = r;
					}
				}
			}
		}
		cout << maxN << " " << maxY << " " << maxR << endl;
		cout << minN << " " << minY << " " << minR << endl;
	}
	return 0;
}

31 素数

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a;
	while (cin >> n)
	{
		for (int i = 1; i <= n; i++)
		{
			int tag = 0;
			cin >> a;
			int t = 2;
			while (t <= a / 2)
			{
				if (a % t == 0)
				{
					tag = 1;
					break;
				}
				t++;
			}
			if (tag) cout << "no" << endl;
			else {
				cout << "yes" << endl;
			}
		}
	}
	return 0;
}

32 计算e

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double th,sum=0;
	while (cin >> th)
	{
		sum = 0;
		int count = 0;
		double i = 1.0;
		while (i >= th)
		{
			sum += i;
			count++;
			i /= double(count);
		}
		cout << fixed << setprecision(6) << sum << " " << count << endl;
	}
	return 0;
}

33 数字之和

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while (cin >> n)
	{
		int sum = 0;
		int t = n;
		while (t != 0)
		{
			sum += (t % 10);
			t /= 10;
		}
		cout << sum << endl;
	}
	return 0;
}

34 繁殖问题

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int now[51];
int main()
{
	int n;
	while (cin >> n)
	{
		
		for (int i = 0; i <= 51; i++) now[i] = 0;
		now[1] = 1;
		for (int j = 3; j<= n; j++)
		{
			if (j - 2 > 0) now[j] += now[j - 2];
			if (j - 3 > 0) now[j] += now[j - 3];
			if (j - 4 > 0) now[j] += now[j - 4];
			if (j - 6> 0) now[j - 6]=0;
		}
		int sum = 0;
		for (int k = 1; k <= n; k++)
		{
			sum += now[k];
		}
		cout << sum << endl;
	}
	return 0;
}

35 奇妙的数字

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
long magic[10];
long he(long a)
{
	int t = 0;
	while (a)
	{
		t += a % 10;
		a /= 10;
	}
	return t;
}
int main()
{
	int n;
	for (int i = 0; i <= 10; i++) magic[i] = 0;
	int count = 0;
	while (cin >> n)
	{
		for (long j = 8899; count < 10; j++)
		{
			if (he(j) % 17 == 0 && he(j + 1) % 17 == 0)magic[count++] = j;
		}
		cout << magic[n - 1] << endl;
	}
	return 0;
}

36 整除的尾数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;

int  getResult(int a, int b, int weishu[])
{
	int c = 0;
	for (int j = 0; j <= 99; j++)
	{
		if ((a * 100 + j) % b == 0)weishu[c++] = j;
	}
	return c;
}
int main()
{
	int a, b, weishu[100], count, i;
	cin >> a;
	cin >> b;
	count = getResult(a, b, weishu);
	for (i = 0; i < count; i++)
	{
		if (i > 0)
			printf(" ");
		printf("%02d", weishu[i]);
	}
	printf("\n");

	return 0;
}

37 黑色星期五

在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, week[7]={0,0,0,0,0,0,0}, month[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	long d=0;
	cin >> n;
	for (int y = 1900; y <= 1900 + n - 1; y++)
	{
		if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0))month[2] = 29;
		else month[2] = 28;
		for (int i = 1; i <= 12; i++)      //12个月鸭!
		{
			for (int j = 1; j <= month[i]; j++)//每天都要判断一下
			{
				++d;
				if (j == 13)
					week[d % 7]++;
			}
		}
	}
	printf("%d %d %d %d %d %d %d", week[6], week[0], week[1], week[2], week[3], week[4], week[5]);
	

	return 0;
}

38 树

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l, m;
	while (cin >> l >> m)
	{
		int x,y, tree[10000] ;
		for (int j = 0; j < l; j++)tree[j] = 1;
		for (int i = 1; i <= m; i++)
		{
			cin >> x >> y;
			for (x; x < y; x++)
			{
				tree[x] = 0;
			}
		}
		int sum = 0;
		for (int j = 0; j < l; j++)
			sum += tree[j];
		cout << sum << endl;
	}
	return 0;
}

39 约瑟夫环

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, x;
	while (cin >> n &&cin>> x) {
		int a[100];
		int i, k = 1;
		for (i = 1; i <= n; i++)
			a[i] = i;
		for (i = n; i >= 1; i--) {
			k = (k + x - 1) % i; 
			if (k == 0) k = i;
			if (i > 1) cout << a[k] << " ";
			else cout << a[k] << endl;
			for (int j = k; j < i; j++)
				a[j] = a[j + 1];
		}
	}
	return 0;
}

40 最大与最小

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m, n;
	while (cin >> m&&cin>> n) {
		int a[100];
		int i, max = 0,min=0X7ffffff,k,t;
		for (i = 0; i < m; i++)
			cin >> a[i];
		for (k=0;k<m;k++)
		{
			t = 0;
			for (int j = 0; j < n; j++)
				t += a[(k + j) % m];
			if (t > max)max = t;
			 if (t < min) min = t;
		}
		cout << "Max=" << max << endl;
		cout << "Min=" << min<< endl;
cout << endl;
	}
	return 0;
}

41 环

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int  n;
	while (cin >> n) {
		int a[9],b[9],temp;
		for (int i = 1; i <= n; i++)
		{
			int cou = 0;
			for (int j = 0; j < 9; j++)
			{
				cin >> a[j];
			}
			for (int i = 0, cut = 0; i < 9; i++, cut++)
			{
				//切开后顺序b[]
				for (int j = 0; j < 9; j++)
				{
					temp = (cut + j) % 9;
					b[j] = a[temp];
				}
				//x为顺序数,y为逆序数
				int x = 0, y = 0;
				for (int j = 0; j < 9; j++)x = x * 10 + b[j];
				for (int j = 8; j >= 0; j--)y = y * 10 + b[j];
				if (x < y) { temp = x; x = y; y = temp; }
				if ((x - y) % 396 == 0)cou++;
			}
			cout << cou << endl;
		}
		
	}
	return 0;
}

42 求数列项

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;long a[51];
	a[0] = 1;
	a[1] = 1;
	a[2] = 5;
	for (int i = 3; i <= 50; i++)
	{
		a[i] = (i-3) * 3 + 7 + a[i - 1];
	}
	while (cin>>n)
	{
		cout << a[n] << endl;
		
	}
	return 0;
}

43 最高频率

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,j;
	int a[110];
	while (cin >> n)
	{	
		for (int i = 0; i < 110; i++)
			a[i] = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >>j ;
			a[j]++;
		}
		int max = 0,size=0;
		for (int i = 1; i< 110; i++)
		{
			if (a[i] > max)
			{
				max = a[i];
				size = i;
			}
		}
		cout << size << endl;
	}
	return 0;
}

44 三艘船

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e,f;
	

	while (cin >> a>>b>>c&&cin>>d>>e>>f)
	{
		int ad=a*d, be=b*e, cf=c*f;
		int a[3]={ad,be,cf};
		while (a[0]!=a[1]||a[0]!= a[2]||a[1]!=a[2])
		{
			int min = a[0],t=0;
			for (int i = 1; i < 3; i++)
			{
				if (a[i] < min)
				{
					min = a[i];
					t = i;
				}
			}
			switch (t)
			{
			case 0:a[0] += d * 24; break;
			case 1:a[1] += e * 24; break;
			case 2:a[2] += f * 24; break;
			default:
				break;
			}
		}
		cout << a[0]<<endl;
		
	}
	return 0;
}

45 回文数

在这里插入图片描述在这里插入图片描述

#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int a[10];
int test(int i,int &t)
{
	for (int k = 0; k < 10; k++)a[k] = 0;
	int j = 0,b=i;
	while (i != 0)
	{
		a[j++] = i % 10;
		i /= 10;
	}
	t = 0;
	for (int k = 0; k < j; k++)
	{
		t *= 10;
		t += a[k];
	}
	if (t == b)return 1;
	else return 0;
}
int main()
{
	int n;
	while(cin >> n)
	{
		if (n == 0)break;
		int t = 0;
		test(n, t);
		cout << n << "+" << t << "=" << n + t << endl;
		int s = n + t;
		while (!test(s, t))
		{
			 cout << s << "+" << t << "=" << s + t << endl;
			 s += t;
		}
	}
	return 0;
}

46 特殊四位数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int s[50], j = 0, a, b, c, d;
	for (int i = 34; i < 100; i++)
	{
		int t = i * i;
		d = t % 10;
		t /= 10;
		c = t % 10;
		t /= 10;
		b = t % 10;
		t /= 10;
		a = t % 10;
		if ((a + c) == (b * d))s[j++] = i * i;
	}
	while (cin >> n)
	{		
		cout << s[n - 1] << endl;;
	}
	return 0;
}
	

47 最大值

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l1,l2,a[20];
	while (cin >> n>>l1>>l2)
	{
		for (int i = 0; i < 20; i++)a[i] = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		int max = a[0];
		for (l1; l1 <= l2; l1++)
		{
			if (l1 > 1)
			{
				int t=0;
				for (int j = 0; j < n-l1+1; j++)
				{
					for (int i = j; i < l1+j; i++)
						t += a[i];
					if (t > max)max = t;
					t = 0;
				}
			}
			else 
			{
				for (int j = 1; j < n; j++)
				{
					if (a[j] > max) max = a[j];
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}


48 数列1

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n, a[51];
	while (cin >> n)
	{
		for (int i = 0; i <n; i++)
		{
			cin >> a[i];
		}
		a[n] = 0;
		int t=0,count=0;
		for (int k = 0; k < n; k++)
		{
			int temp;
			for (int len = 1; k + len <= n; len++)//增加长度,逐个尝试
			{
				temp = 0;
				for (int j = 0; j < len; j++)temp += a[j + k];
				if (temp % 11 == 0)count++;
			}
			
		}
/*		for (int i = 2; i <= n; i++)
		{
			for (int j = 0; j < n - i + 1; j++)
			{
				for (int i = j; i <i+j; i++)	t+= a[i];
				if (t % 11 == 0)	count++;
				t = 0;
			}
		}*/
		cout << count << endl;
	}	
	return 0;
}


49 修理牛棚

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void sort(int arr[], int len)
{
    for (int i = 1; i < len; i++)
    {
        int num = arr[i];
        int left = 0;// 左区间
        int rigth = i - 1;// 右区间
        while (left <= rigth)
        {
            int mid = (left + rigth) / 2;// 中间位置
            if (num < arr[mid])// 要插入的位置还在左边
            {
                rigth = mid - 1;
            }
            else
            {
                left = mid + 1;
            }
        }
        for (int j = i - 1; j >= left; j--)// 移动数据
        {
            arr[j + 1] = arr[j];
        }
        if (left != i)
        {
            arr[left] = num;
        }
    }
}
int main()
{
	int m,c ,a[200]={0}, num[200] = {0};
	while (cin >> m >> c)
	{
		for (int i = 0; i < c; i++)
			cin >> num[i];
        
        //排序
        sort(num, c  );
         int  len = num[c - 1] - num[0] + 1;
        for (int i = 0; i <c-1; i++)
        {
            a[i] = num[i + 1] - num[i] - 1;
        }
        sort(a, c - 1);
        for (int i = 0; i < m-1&&len-a[c-2-i]>=0; i++)
        {
            len-=a[c-2-i];
        }
        
        cout << len<<endl;
	}

	return 0;
}

50 按要求输出序列

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void sort(int arr[], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j < n-i; j++)
		{
			if (arr[j-1] > arr[j])
			{
				int temp = arr[j-1];
				arr[j-1] = arr[j];
				arr[j] = temp;
			}
		}
	}
}
void delete_(int arr[], int &len)
{
	int b[200]={0},i,j=0;
	for (i = 0; i < len-1; i++)
	{
		if (arr[i] != arr[i + 1])b[j++] = arr[i];
	}
	b[j++] = arr[i];
	len = j;
	for (i = 0; i < len; i++)
		arr[i] = b[i];
}
int main()
{
	int n,a[200];
	while (cin >> n)
	{
		for (int i = 0; i < n; i++)
			cin >> a[i];
		sort(a, n);
		int len = n;
		delete_(a, len);
		for (int i = 0; i < len; i++)
		{
			if (i < len - 1)cout << a[i] << " ";
			else
			{
				cout << a[i] << endl;
			}
		}
	}
	return 0;
}

51 部落人乘法

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, s[200];
	while (cin >> a >> b)
	{
		int t1 = a, t2 = b;
		int  i = 0;
		while (t1 != 0)
		{
			if (t1 % 2 == 1)s[i++] = t2;
			t1 /= 2;
			t2 *= 2;
		}
		cout << a << "*" << b << "=";
		int t = 0;
		for (int j = 0; j < i - 1; j++)
		{
			cout << s[j] << "+";
			t += s[j];
		}
		cout << s[i - 1] << "=" << t + s[i - 1] << endl;

	}
	return 0;
}

52 序列

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[200];
	while (cin >> n)
	{
		int t = 0,j=0, i = 1;
		while (t< n)
		{
			if (t + i > n) //如果超出了范围那么就把多的分到前面去
			{
				int m = j - 1; int k = 1,b=n-t;
				for (; k <=b; )
				{
					a[m]+=1;
					t++;
					m--;
					k++;
				}	
			}
			else //先保持递增次序
			{
				t += i;
				a[j++] = i;
				i++;
				
			}
		}
		for (int i = 0; i < j-1; i++)
		{
			cout << a[i] << ",";
		}
		cout << a[j-1] << endl;
		
	}
	return 0;
}

53 双重回文数

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long transtwo(int a)
{
	int t[1000],i=0;
	while (a)
	{
		t[i++] = a % 2;
		a /= 2;
	}
	long b = 0;
	for (int j = i - 1; j >= 0; j--)
	{
		b *= 10; 
		b += t[j];
	}
	return b;
}

bool isok(long long int a)
{
	int t[10000],i=0;
	while (a)
	{
		t[i++] = a % 10;
		a /= 10;
	}
	if (i == 1) return true;
	for (int j = 0; j < i/2; j++)
	{
		if (t[j] != t[i - j - 1]) return false;

	}
	return true;
}
int main()
{
	int n, s, a[16];
	while (cin >> n >> s)
	{
		for (int i = s + 1, c = 0; c < n; i++)
		{
			
			int f = 0;
			for (int k=2;k<=10&&f<2;k++)
			{
				int t[1000],d = 0,e = i;;
				while (e)
				{
					t[d++] = e % k;
					e /= k;
				}
				long  long int  b = 0;
				for (int j = d - 1; j >= 0; j--)
				{
					b *= 10;
					b += t[j];
				}
			
				if (isok(b)) f++;
			}

			if (f >= 2)a[c++] = i;
			
		
		}
		for (int i = 0; i < n; i++) cout << a[i] << endl;
	}
	return 0;
}

54 等差数列(难)

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n, m, s[100000]={0}, i = 0, j = 0, a = 0, b = 0, scope = 0;
	int flag = 0;  //标记是否找到满足条件的数列,默认没有找到
	while (cin >> n >> m)
	{
		scope = m * m * 2;
		for (i = 0; i <= m; i++)
		{ //找出双平方数集合
			for (j = i; j <= m; j++)
			{
				s[i * i + j * j] = 1;
			}
		}
		for (b = 1; (n - 1) * b <= scope; b++) {//从b开始,保证先按照b排序,再按a排序
			for (a = 0; a + ((n - 1) * b) <= scope; a++) {
				for (i = 0; i <= n - 1; i++) {
					if (s[a + i * b] == 0) {
						break;
					}
				}
				if (i > n - 1) {
					flag = 1;
					printf("%d %d\n", a, b);
				}
			}
		}
		if (flag == 0) {
			printf("NONE\n");
		}
	}
	return 0;
}

55 人见人爱A-B

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	while (cin >> t)
	{
		for (int i = 0; i < t; i++) {
			int n, m;
			cin >> n >> m;
			set<int>s;
			int temp;
			for (int j = 0; j < n; j++) {
				cin >> temp;
				s.insert(temp);
			}
			for (int j = 0; j < m; j++) {
				cin >> temp;
				if (s.find(temp) != s.end()) {
					s.erase(temp);
				}
			}
			if (s.size() == 0) {
				cout <<"NULL"<< endl;
			}
			else {
				set<int>::iterator it;
				for (it = s.begin(); it != s.end(); it++) {
					cout << *it<<" ";
				}
			}
			cout << endl;
		}
	}
	return 0;
}

56 最少拦截系统

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int T,N,a[1000];
	while (cin >>T)
	{
		for (int i = 1; i <= T; i++)
		{
			cin >> N;
			for (int i = 0; i < 1000; i++)
			{
				a[i] = 0;
			}
			for (int i = 0; i < N; i++)
			{
				cin >> a[i];
			}
			int c = 0,t,time=0; //最少导弹
			while (c < N)
			{
				for (int i = 0; i < N; i++) 
				{
					if (a[i] != 0)
					{
						t = a[i]; 
						a[i] = 0;
						c++;
						//cout << "time=" << time << " a[i]=" << t << " c=" << c << endl;
						break;
					}
				}
				time++;
				for (int i = 1; i < N; i++)
				{
					if (t > a[i]&&a[i]!=0)
					{
						t = a[i]; c++;
						//cout << "time=" <<time<<" a[i]="<<t<<" c="<<c<<endl;
						a[i] = 0;	
					}
				}
			}
			cout << time << endl;
		}
	}
	return 0;
}

57 求N!

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	while (cin >>n)
	{
		int a[1000] = { 0 };
		a[0] = 1;
		int t = 0, length = 1;
		if (n == 0 || n == 1)cout << "1" << endl;
		else if (n == 2)cout << "2" << endl;
		else
		{
			int i, j, len = 0, rem = 0;
			for (i = 2; i <= n; i++)//将每次的阶乘结果在数组中倒序存储,每次与i相乘之后与10求余个位留下,十位进到数组的下一位
			{
				for (j = 0; j <= len; j++)
				{
					rem += a[j] * i;
					a[j] = rem % 10;
					rem /= 10;
					if (j == len && rem != 0) len++;//如果数组已满且rem中不为零则需要将数字长度加一
				}
			}
			for (i = len; i >= 0; i--)//将数组倒序输出
				cout << a[i];
			cout << endl;
		}
	}
	return 0;
}

58 素数表

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool sushu(int a)
{
	if (a == 1) return false;
	for (int i = 2; i <= a / 2; i++)
	{
		if (a % i == 0) return false;
	}
	return true;
}
int main()
{
	int m, n,a[1000];
	while (cin >> m >> n)
	{
		int j = 0;
		for (int i = m; i <= n; i++)
		{
			if (sushu(i)) a[j++] = i;
		}
		for (int i = 0; i < j; i++)
		{
			if (i % 10 != 9)
			{
				cout << a[i] << " ";
			}
			else {
				cout <<a[i]<<" "<< endl;
			}
		}
		
	}
	return 0;
}

59 倒数数列

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
double total(int a)
{
	double sum = 0;
	for (int i = 1; i <= a; i++)
	{
		sum += 1.0 / i;
	}
	return sum;
}
int main() {
	int n;
	cin >> n;
	cout << fixed << setprecision(3) << total(n) << endl;
	return 0;

}

60 排列数

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int  fact(int a)
{
	int s = 1;
	for (int i = 1; i <= a; i++) s *= i;
	
	return s;
}

int main() {

	int n,m;

	cin >>m>> n;

	cout << fixed << setprecision(3) <<fact(m)/fact(m-n) << endl;

	return 0;
}

61 亲和数

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool  qinheshu(int m,int n)
{
	int a[1000], b[1000];
	a[0] = 1;
	b[0] = 1;
	int j = 1,k=1;
	for (int i = 2; i < m; i++)
	{
		if (m % i == 0)a[j++] = i;
	}
	int s = 0;
	for (int i = 0; i < j; i++)s += a[i];
	if (s != n)return false;
	else
	{
		int j = 1, k = 1;
		for (int i = 2; i < n; i++)
		{
			if (n % i == 0)b[j++] = i;
		}
		int s = 0;
		for (int i = 0; i < j; i++)s += b[i];
		if (s != m)return false;
		else { return true; }
	}

}

int main() {

	int  m;

	while (cin >> m)
	{
		int a, b;
		for (int i = 1; i <= m; i++)
		{
			cin >> a >> b;
			if (qinheshu(a, b)) cout << "YES"<<endl;
			else {
				cout << "NO"<<endl;
			}
		}
	}

	return 0;

}

62 分拆素数和

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool sushu(int a)
{
	if (a == 1) return false;
	for (int i = 2; i <= a / 2; i++)
	{
		if (a % i == 0) return false;
	}
	return true;
}
int  sushuhe(int m)
{
	int c = 0;
	for (int i = 2; i < m / 2; i++)
	{
		if (sushu(i) && sushu(m - i)) c++;
	}
	return c;
}

int main() {
	int  t;
	while (cin >> t)
	{
		int a;
		for (int i = 1; i <= t; i++)
		{
			cin >> a ;
			cout << sushuhe(a) << endl;
		}
	}
	return 0;
}

63 歌德巴赫猜想

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool sushu(int a)
{
	if (a == 1) return false;
	for (int i = 2; i <= a / 2; i++)
	{
		if (a % i == 0) return false;
	}
	return true;
}
void  sushuhe(int m)
{	
	for (int i = 2; i <= m / 2; i++)
	{
		if (sushu(i) && sushu(m - i))
		{
			cout << i << " " << m - i << endl; break;
		}
	}
}

int main() {

	int  t;

	while (cin >> t)
	{
		int a;
		for (int i = 1; i <= t; i++)
		{
			cin >> a;
			sushuhe(a);

		}
	}

	return 0;

}

64 N的倍数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void findminbeishu(int a)
{
	int flag = 1,t;
	for (int i = 1; flag == 1; i++)
	{
		 t=a * i;
		while (t != 0)
		{
			if (t % 10 == 0 || t % 10 == 1)
				t /= 10;
			else
			{
				break;
			}
		}
		if (t == 0)
		{
			flag = 0; 
			cout << a*i << endl;
		}
	}
}
int main() {

	int  n;

	while (cin >> n)
	{
		findminbeishu(n);
		
	}
	return 0;
}

65 求n天后的日期

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void riqi(int  year, int month, int day, int n)
{
	int months[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	
	day = day + n;
	while (day > months[month]) {
		if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
			months[2] = 29;//可能接下来还会出现闰年 
		}
		else {
			months[2] = 28;
		}
		day = day - months[month];
		month++;
		if (month > 12)
		{
			year++;
			month = month - 12;
		}
	}
	cout << year << " " << month << " " << day << endl;

}
int main() {

	int  year, month, day,n;

	cin >> year >> month >> day >> n;
	riqi(year, month, day, n);

	return 0;

}

66 菱形输出

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	char a[26]={ 'A', 'B', 'C' ,'D', 'E' ,'F','G','H','I', 'J', 
		'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S','T', 'U', 'V', 'W', 'X','Y', 'Z'};
	while (cin >> n)
	{
		int i=0,j=0,count=1;
		for (i = 1; i <= n; i++)
		{
			for (j = 0; j < n - i; j++) cout << " ";
			if (i == 1)cout << a[26-count++] << endl;
			else 
			{
				cout << a[26 - count];
				count++;
				for(int k=1;k<=2*(i-2)+1;k++)cout << " ";
				cout << a[26 - count] << endl;
				count++;
			}
		}
		for (i=n+1; i <= 2*n-1; i++)
		{
			for (j = 0; j < i-n; j++) cout << " ";
			if (i == 2*n-1)cout << a[26-count++] << endl;
			else 
			{
				cout << a[26 -count++];
				for (int k = 1; k <= 2 * (i - 2-2*j) + 1; k++)cout << " ";
				cout << a[26 - count++] << endl;
			}
		}
		cout << endl;
	}
	return 0;
}

67 三角形的个数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool isok(int a, int b, int c)
{
	if ((a + b > c) && (a + c > b) && (b + c > a)) return true;
	else return false;
}
int main()
{
	int n,a,b,c;
	while (cin >> n)
	{
		int count = 0;
		for (a = 1; a < n / 3; a++)
		{
			for (b = a + 1; b < n / 2; b++)
			{
				c = n - a - b;
				if (isok(a, b, c)&&c>b)
				{
					count++;
					//cout << a << " " << b << " " << c << " " << count << endl;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

68 素数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
bool sushu(long a)
{
	if (a == 1) return false;
	for (int i = 2; i <= sqrt(a); i++)
	{
		if (a % i == 0) return false;
	}
	return true;
}
int main()
{
	long  n, m;
	while (cin >> m >> n)
	{
		long count = 0;
		for (long i = m; i <= n; i++)
		{
			if (sushu(i))count++;
		}
		cout << count << endl;
	}
	return 0;
}

69 杨辉三角在这里插入图片描述

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void yanghui(int n)
{
	int a[1000], count = 3;
	a[0] = 1; a[1] = 1; a[2] = 1;
	
		for (int i = 1; i <= n; i++)
		{
			if (i == 1)cout << 1 << endl;
			if (i == 2)
			{
				cout << 1 << " " << 1 << endl;
			}
			if (i > 2)
			{
				cout << 1 << " ";
				a[count++] = 1;//首位都是1
				for (int j = 1; j < i -1; j++)
				{
					a[count] = a[count - i] + a[count - i +1];
					/*cout<<"a[count - i] + a[count - i +1]分别为"<< a[count - i] <<" " << a[count - i - 1]<<" ";
					cout << "count 为" << count<<" i:"<<i<<" ";*/
					cout << a[count] << " ";
					count++;
				}
				cout << 1 << endl;
				a[count++] = 1;

			}
		}
}

int main()
{
	int  n,m;
	while (cin >> n)
	{
		for (int i = 1; i <= n; i++)
		{
			cin >> m;
			yanghui(m);
cout << endl;
		}
	}
	return 0;
}

70 矩阵问题

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void juzhen(int n)
{
	
	for (int i = 1; i <= 2 * n + 1; i++)
	{
		for (int j = 1; j <= 2 * n+1; j++)
		{
			if (i<=n)
			{
				if (j < i)cout << 4 << " ";
				if (j == i)cout << 1 << " ";
				if (j > i && j <= 2 * n + 1 - i)cout << 2 << " ";
				if (j == 2 * n + 2 - i)
				{
					if (j < 2 * n + 1) cout << 1 << " ";
					else cout << 1;
				}
				if (j > 2 * n + 2 - i)
				{
					if (j < 2 * n + 1)cout << 5 << " ";
					else cout << 5;
				}
			}
			else if (i == n + 1)
			{
				if (j < i)cout << 4 << " ";
				if (j == i)cout << 1 << " ";
				if (j > i )
				{
					if (j < 2 * n + 1)cout << 5 << " ";
					else cout << 5;
				}
			
			}
			else
			{
				
				if (j < 2 * n + 2 - i)cout << 4 << " ";
				if (j == 2 * n + 2 - i)cout << 1 << " ";
				if (j > 2 * n + 2 - i && j < i)cout << 3<< " ";
				if (j == i)
				{
					if (j < 2 * n + 1) cout << 1 << " ";
					else cout << 1;
				}
				if (j > i )
				{
					if (j < 2 * n + 1)cout << 5 << " ";
					else cout << 5;
				}
			}
		}
		cout <<endl;

	}
}
int main()
{
	int  n;
	while (cin >> n)
	{
		juzhen(n);
	}
	return 0;
}

71 发牌

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef struct {
	char ch;
	int num;
}card;
int main()
{
	int n, i, j, count, k = 0;
	card c[52];
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			switch (i) {
			case 0:c[k].ch = 'c'; break;
			case 1:c[k].ch = 'd'; break;
			case 2:c[k].ch = 'h'; break;
			case 3:c[k].ch = 's'; break;
			}
			c[k++].num = j;
		}
	}
	while (cin >> n)
	{
		count = 0;
		for (i = n - 1; i < 52; i = 4 * count + (n - 1)) {
			if (count == 12) {
				cout << c[i].ch << " " << c[i].num << endl;
			}
			else {
				cout << c[i].ch << " " << c[i].num <<" ";
			}
			++count;
		}
	}
	return 0;
}

72 数字金字塔(动态规划)

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
	int n, a[100][100], b[100][100];
	while (cin >> n)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j <= i; j++)
			{
				cin >> a[i][j];
			}
		}
		b[0][0] = a[0][0];
		for (int i = 1; i < n; i++)
		{
			for (int j = 0; j <= i; j++)
			{
				if (i == 1)
				{
					b[i][j] = b[0][0] + a[i][j];
				}
				else
				{
					if (j == 0)
					{
						b[i][j] = b[i - 1][j] + a[i][j];
					}
					else if (j == i)
					{
						b[i][j] = b[i - 1][j - 1] + a[i][j];
					}
					else
					{
						int max = b[i - 1][j - 1];
						if (max < b[i - 1][j]) max = b[i - 1][j];
						b[i][j] = max + a[i][j];
					}
				}

			}
		}
		int maxZ = b[n - 1][0];
		for (int j = 1; j < n; j++)
		{
			if (maxZ < b[n - 1][j])maxZ = b[n - 1][j];
		}
		cout << maxZ << endl;


	}
	return 0;
}

73 稀疏矩阵

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;

int main()
{
	int m, n,a[20][20];
	while (cin >> m >> n)
	{
		for (int i = 0; i < m; i++)
			{
				for (int j = 0; j < n; j++)
				{
					cin >> a[i][j];
				}
			}
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (a[i][j] != 0)
				{
					cout << i + 1 << " " << j + 1 << " " << a[i][j] <<endl;
				}
			}
		}
		cout << endl;
	}
	
	return 0;
}

74 矩阵转换

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
	int  n, a[20][20];
	while (cin  >> n)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> a[i][j];
			}
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < i+1; j++)
			{
				if (i != j)
				{
					int temp = a[i][j];
					a[i][j] = a[j][i];
					a[j][i] = temp;
				}
			}
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (j < n - 1)
				{
					cout << a[i][j] << " ";
				}
				else {
					cout << a[i][j] << endl;
				}
			}
		}
		cout << endl;
	}

	return 0;
}

75 魔方阵

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
	int  n, temp[20][20], i, j, lastrow, lastcol, row, col;
	while (cin >> n)
	{
		if (n == 1) 
			cout << 1 << endl;
		else 
		{
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					temp[i][j] = 0;
				}
			}
			
			temp[0][(n - 1) / 2] = 1;
			lastrow = 0; lastcol = (n - 1) / 2;
			for (i = 2; i <= n*n; i++) {
				row = lastrow;
				col = lastcol;
				--row;
				++col;
				if (row == -1) {
					row = n - 1;
				}
				if (col == n) {
					col = 0;
				}
				if (temp[row][col] != 0 || (lastrow == 0 && lastcol == n - 1)) {
					row = lastrow + 1;
					col = lastcol;
				}
				temp[row][col] = i;
				lastcol = col;
				lastrow = row;
			}

			for (i = 0; i < n; i++) {
				for (j = 0; j < n; j++) {
					printf("%d", temp[i][j]);
					if (j == n - 1) {
						printf("\n");
					}
					else {
						printf(" ");
					}
				}
			}
		}
		printf("\n");

		}

	return 0;
}

76 最大效益

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
	int a[5][5];
	while (cin >> a[0][0])
	{
		for (int i = 0; i < 5; i++)
		{
			for (int j = 0; j < 5; j++)
			{
				if (i == 0 && j == 0)continue;
				
				cin >> a[i][j];
			}
		}
		int maxS = 0, maxI = 0, maxJ = 0, sum = 0;
		for (int k = 0; k < 5; k++)
		{
			for (int i = 0; i < 5; i++)
			{
				for (int j = 0; j < 5; j++)
				{
					if (maxS < a[i][j])
					{
						maxS = a[i][j];
						maxI = i;
						maxJ = j;
					}
				}
			}
			sum += maxS;
			maxS = 0;
			for (int i = 0; i < 5; i++)
			{
				a[i][maxJ] = 0;
			}
			for (int j = 0; j < 5; j++)
			{
				a[maxI][j] = 0;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

77 螺旋方阵

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
	int a[10][10],b[10][10], n;
	while (cin >>n)
	{
		int count = 1;
		for (int i = 0; i < 10; i++)//也可以全部a矩阵置0
		{
			for (int j = 0; j < 10; j++)
			{
				b[i][j] = -1;
			}
		}
		
		int flag = 0,t,a1=0,a2=0,a3=0,a0=0;
		while (flag < (2 * n-1))
		{
			t = flag % 4;
			switch (t)
			{
			case 0:for (int i = 0; i < n; i++)//向右
					{
						if (b[a0][i] == -1)
						{
							a[a0][i] = count++;
							b[a0][i] = 0;

						}
					}
				  a0++;
				  flag++;
				  break;
			case 1:for (int i = 0; i < n; i++)//向下
			{
				if (b[i][n - 1-a2] == -1)
				{
					a[i][n - 1-a2] = count++;
					b[i][n - 1-a2] = 0;
				}
			}
				  a2++;
				  flag++;
				  break;
			case 2:	for (int i = n - 1; i >= 0; i--)//向左
					{
						if (b[n - 1-a3][i] == -1)
						{
							a[n - 1-a3][i] = count++;
							b[n - 1-a3][i] = 0;
						}
					}
				  a3++;
				  flag++;
				  break;
			case 3:	for (int i = n - 1; i >= 0; i--)//向上
					{
						if (b[i][a1] == -1)
						{
							a[i][a1] = count++;
							b[i][a1] = 0;
						}
					}
				  a1++;
				  flag++;
				  break;

			default:
				break;
			}
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (j == n - 1)cout << a[i][j] << endl;
				else
				{
					cout << a[i][j] <<" ";
				}
			}
		}
		cout << endl;
	}
	return 0;
}

78 方块转换

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
	char a[10][10], b[10][10],c[10][10], t[10][10];
	int n;
	while (cin >> n)
	{
		int count = 1;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> a[i][j];
			}
		}
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> b[i][j];
			}
		}
		int flag = 1,d = 1;
		while (count <= 7 && flag)
		{
			switch (count)
			{
			case 1:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						t[j][n - 1 - i] = a[i][j];
					}
				}
				break;
			case 2:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						t[n - 1 - i][n - 1 - j] = a[i][j];
					}
				}
				break;
			case 3:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						t[n - 1 - j][i] = a[i][j];
					}
				}
				break;
			case 4:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						t[i][n - 1 - j] = a[i][j];
					}
				}
				break;
			case 5:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						c[i][n - 1 - j] = a[i][j];
					}
				}
				
				while (d <= 3)
				{
					switch (d)
					{
					case 1:
						for (int i = 0; i < n; i++)
						{
							for (int j = 0; j < n; j++)
							{
								t[j][n - 1 - i] = c[i][j];
							}
						}
						break;
					case 2:
						for (int i = 0; i < n; i++)
						{
							for (int j = 0; j < n; j++)
							{
								t[n - 1 - i][n - 1 - j] = c[i][j];
							}
						}
						break;
					case 3:
						for (int i = 0; i < n; i++)
						{
							for (int j = 0; j < n; j++)
							{
								t[n - 1 - j][i] = c[i][j];
							}
						}
						break;
					}
					for (int i = 0; i < n && flag; i++)
					{
						for (int j = 0; j < n && flag; j++)
						{
							if (b[i][j] != t[i][j])
							{
								flag = 0;
								break;
							}
						}
					}
					if (flag == 1)
					{
						d = 4;
						break;

					}
					else
					{
						flag = 1;
						d++;
					}
				}
				break;
			case 6:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						t[i][j] = a[i][j];
					}
				}
				break;
			case 7:
				for (int i = 0; i < n; i++)
				{
					for (int j = 0; j < n; j++)
					{
						t[i][j] = b[i][j];
					}
				}
				break;

			default:
				break;
			}

			for (int i = 0; i < n && flag; i++)
			{
				for (int j = 0; j < n && flag; j++)
				{
					if (b[i][j] != t[i][j])
					{
						flag = 0;
						break;
					}
				}
			}
			if (flag == 1)
			{
				
				cout << count << endl;
				break;
			}
			else
			{
				flag = 1;
				count++;
			}


		}

	}
	return 0;
}

79 阵列(不会)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

80 饲料调配

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;

int main()
{
	int a[11][11], x,y,z;
	while (cin >> x >> y >> z)
	{
		int a0 = 1, a1 = 1, a2 = 1, t1=0, t2=0, t3=0, b1=0, flag = 1;
		for (int i = 0; i < 3; i++)
		{
			for (int j = 0; j < 3; j++)
				cin >> a[i][j];
		}	
		for (a0 = 0; a0 < 100 && flag==1; a0++)
		{
			for (a1 = 0; a1 < 100 && flag==1; a1++)
			{
				for (a2 = 1; a2 < 100 && flag==1; a2++)
				{
					t1 = a0 * a[0][0] + a1 * a[1][0] + a2 * a[2][0];
					if(t1%x==0) 
					{
						b1 = t1 / x;
						t2 = a0 * a[0][1] + a1 * a[1][1] + a2 * a[2][1];
						if(b1*y==t2)
						{
							t3 = (a0 * a[0][2] + a1 * a[1][2] + a2 * a[2][2]);
							if (b1*z==t3)
							{
								//cout << t1 << " " << t2 << " " << t3 << endl;
								cout  << a0 << " " << a1 << " " << a2 << " " << b1  << endl;
								flag = 0;
							}
						}
					}
				}
			}
		}
		if (flag == 1)cout << "NONE";
	}
	return 0;
}

81 求小数位数个数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;

int main()
{
	char n[100];
	while (cin >> n)
	{
		int count = 0,i=0;
		while (n[i] != '.')i++;
		while (n[++i] != '\0')count++;
		cout << count << endl;
	}
	return 0;
}

82 进制转换

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;

int main()
{
	char a[100];
	int m, n;
	while (cin >>m>> n)
	{
		int temp,i=0;
		if (n == 10||m==0) cout << m << endl;
		else 
		{
			while (m)
			{
				temp = m %n;
				if (temp >= 10)
				{
					temp -= 10;
					a[i++] = temp + 'A';
				}
				else 
				{
					a[i++]=temp+'0';
				}
				m /= n;
			}	
		}
		for (int j = i-1; j >=0; j--)
		{
			if (j != 0)cout << a[j];
			else cout << a[j] << endl;
		}
		
	}
	return 0;
}

83 表达式求值在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{
	char a[1000],b[1000];
	int sum = 0, i=0, j=0, temp=0;
	while (gets(a))
	{
		sum = 0;
        memset(b, 0, sizeof(b));
        b[0] = '+';
		j = 1;
		for (i = 0; i < strlen(a); i++)
			if (a[i] != ' ') b[j++] = a[i];
        for (i = 0; i < strlen(b); i++)
        {
            if (b[i] == '+' || b[i] == '-')
            {
                j = i + 1;
                temp = 0;
                while (b[j] != '+' && b[j] != '-' && b[j] != '\0')
                    temp = temp * 10 + (b[j++] - '0');
                if (b[i] == '+')
                    sum += temp;
                else sum-= temp;
                i = j - 1;//返回
            }
        }
		
		cout << sum << endl;
	}
	return 0;
}

84 删除字符

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include <stdio.h>
using namespace std;

int main()
{
	char a[100],c;
	int j=0;
	fgets(a,100 , stdin);
	cin.get( c);
	for (int i = 0; i < strlen(a); i++)
	{
		if (a[i] != c) cout<<a[i];
	}
	return 0;
}

85 手机短号

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include <stdio.h>
using namespace std;

int main()
{
	char a[100],b[7];
	int j=1,n;
	b[0] = '6';
	while (cin>>n)
	{
		for (int i = 0; i < n; i++)
		{
			j = 1;
			for (int c = 0; c < 11; c++)
			{
				cin >> a[c];
			}
			for (int k = 6; k < 11; k++)
			{
				b[j++] = a[k];
			}
			for (int f= 0; f < 6; f++)
			{
				cout << b[f];
			}
			cout << endl;
		}
	}
	
	
	return 0;
}

86 字符串统计

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include <stdio.h>
using namespace std;
int main()
{
	int j = 0, n;
	char a[100];
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++)
	{
		j = 0;
		memset(a, 0, sizeof(a));
		fgets(a,100,stdin);
		for (int k = 0; k < strlen(a); k++)
		{
			if(a[k]>='a'&&a[k]<='z')j++;
		}
		cout << j << endl;
		}
	return 0;
}

87 弟弟的作业(string转int)

		//将string 类型转化为int类型
		stringstream sstream;
		sstream << c;
		sstream >> c1;

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
int main()
{
	int count = 0;
	int a, b;
	char d, e; //  +/- =
	string c; //最后一个数可能是?也可能是整数
	int c1; //将string转化为int类型的数
	while (cin >> a >> d >> b >> e >> c)
	{
		if (c.find('?') == 0)//找到?返回它的索引
		{
			continue;
		}
		else
		{
			//将string 类型转化为int类型
			stringstream sstream;
			sstream << c;
			sstream >> c1;
			if (d == '+')
			{
				if (a + b == c1)
				{
					count++;
				}
			}
			if (d == '-')
			{
				if (a - b == c1)
				{
					count++;
				}
			}
		}
	}
	cout << count << endl;

	return 0;
}

88 字符串排序在这里插入图片描述

在这里插入图片描述

#include<stdio.h>
#include<string.h>
void sort(char a[])
{
    int i,j,t;
    for(i=0;i<strlen(a)-1;i++)
    {
        for(j=0;j<strlen(a)-1-i;j++)
        {
            if(a[j]>a[j+1])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
}
int main(){
    char a[1010];
    while(gets(a))
    {
       // sort(a);
        int j = strlen(a);
		//cout << j << endl;
		sort(a,a+j);//stl的sort方法可以直接调用
        printf("%s\n",a);
    }
    return 0;
}

89 回文问题

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
bool ishui(char a[],int low,int high)
{
	int mid = (low + high+1) / 2;
	for (int i = 0; i < mid; i++)
	{
		if (a[i] != a[high - i])return false;
	}
	return true;
}
int main()
{

	char a[200];
	//memset(a, 0, sizeof(a));
	while (gets(a))
	{
		int j = strlen(a);
		//cout << j<<endl;
		if (ishui(a, 0, j- 1))cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

90 字符串中找整数

在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
int main()
{

	char a[200],b[200];
	//memset(a, 0, sizeof(a));
	while (gets(a))
	{
		int j = strlen(a);
		int count = 0,k=0;
		for (int i = 0; i < j; )
		{
			while (i<j&&(a[i] < '0' || a[i]>'9'))i++;
			if (i < j)count++;
			else break;
			while (i < j && a[i] >= '0' && a[i] <= '9')
			{
			
				b[k++] = a[i++];
			}
			b[k++] = ',';
		}
		if(k>1)	cout << count <<" ";
		else cout << count ;

		int flag = 0;
		for (int i = 0; i < k-1; i++)
		{
			if (b[i] == ',')
			{
				cout << " ";
				flag = 0;
			}
			else
			{
				if (flag == 0 && (b[i - 1] == ',' || b[i - 1] == '0'||i-1<0) && b[i] == '0')
				{
					continue;
				}
				else 	cout << b[i];
				if (b[i] != 0)flag = 1;
			}
		}
		cout << endl;
	}
	return 0;
}

91 乒乓球

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
int main()
{
	char a[200],b[200];
	int d[100]={0};
	//memset(a, 0, sizeof(a));
	int i = 0,j=0,w=0,l=0,c,d1;
	while (cin>>a[0])
	{
		for (i = 1; ;i++)
		{
			cin >> a[i];
			if (a[i] == 'E')
			{
				break;
			}
		}
		d1 = 0;
		w = 0;
		l = 0;
		for (i = 0; i < strlen(a)&&a[i]!='E'; i++)
		{
			if (a[i] == 'W')w++;
			if (a[i] == 'L')l++;
			if (w >= l)
			{
				c = w - l;
				if (c >= 2 && w >= 11)
				{
					d[d1++] = w;
					d[d1++] = l;
					w = 0; l = 0;
					continue;
				}
			}
			else
			{
				c = l - w;
				if (c >= 2 && l >= 11)
				{
					d[d1++] = w;
					d[d1++] = l;
					w = 0; l = 0;
					continue;
				}
			}	
		}
		if (a[i] == 'E'&&(w!=0||l!=0))
		{
			d[d1++] = w;
			d[d1++] = l;
			w = 0; l = 0;
		}
		for (int k = 0; k < d1; k++)
		{
			int c = k + 1;
			cout << d[k] << ":" << d[c] << endl;
			k = c;
		}
		cout << endl;
		d1 = 0;
		w = 0; 
		l = 0;
		for (j = 0; j < strlen(a) && a[j] != 'E';j++)
		{

			if (a[j] == 'W')w++;
			if (a[j] == 'L')l++;
			if (w >= l)
			{
				c = w - l;
				if (c >= 2 && w >= 21)
				{
					d[d1++] = w;
					d[d1++] = l;
					w = 0; l = 0;
					continue;
				}
			}
			else
			{
				c = l - w;
				if (c >= 2 && l >= 21)
				{
					d[d1++] = w;
					d[d1++] = l;
					w = 0; l = 0;
					continue;
				}
			}
		}
		if (a[j] == 'E' &&(w != 0 || l != 0))
		{
			d[d1++] = w;
			d[d1++] = l;
		}
		for (int k = 0; k < d1; k++)
		{
			int c = k + 1;
			cout << d[k] << ":" << d[c] << endl;
			k = c;
		}
		cout << endl;
	}
	return 0;
}

92 字符串统计

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
int pos(char a[], int low, int high)
{
	
	char c = a[low];
	while (low < high)
	{
		while (low < high && a[high] >=c) --high;
		a[low] = a[high];
		while (low < high && a[low] <= c)++low;
		a[high] = a[low];
	}
	a[low] = c;
	return low;
}
void quicksort(char a[],int low,int high)
{
	if (low < high)
	{
		int i = pos(a, low, high);
		quicksort(a, low, i - 1);
		quicksort(a, i + 1, high);
	}
}
int  delete_c(char a[])
{
	int j = 1;	
	
	for (int i = 1; i < strlen(a); i++)
	{
		if (a[i-1] != a[i]) 
		{
			a[j++] = a[i];
		}
	}
	return j;
	

}
int main()
{

	char a[200],b[200];
	int c[100]={0};
	int i = 0,j=0,len2=0,len1;
	while (gets(a))
	{
		gets(b);
		len1 = strlen(a);
		len2 = strlen(b);
		memset(c, 0, sizeof(c));
		for (i = 0; i < len1; i++)
			if (!c[a[i] - 'a']) c[a[i] - 'a']++;
		for (i = 0; i < len2; i++)
			if (c[b[i] - 'a'] == 1) c[b[i] - 'a']++;
			else if (c[b[i] - 'a'] == 0) c[b[i] - 'a']--;
		printf("in s1 or s2:");
		for (i = 0; i < 26; i++)
			if (c[i] != 0) printf("%c", i + 'a');
		printf("\nin s1 and s2:");
		for (i = 0; i < 26; i++)
			if (c[i] == 2) printf("%c", i + 'a');
		printf("\nin s1 but not in s2 ,or in s2 but not in s1:");
		for (i = 0; i < 26; i++)
			if (c[i] == 1 || c[i] == -1) printf("%c", i + 'a');
		printf("\nnot in s1 and s2:");
		for (i = 0; i < 26; i++)
			if (c[i] == 0) printf("%c", i + 'a');
		printf("\n\n");
	
	}
	return 0;
}

93 隐藏口令

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct Str
{
    string arr;
    int space;
};
int main()
{
    char ch;
    int n, i;
    cin >> n;
    getchar();
    string ans;
    Str s[1000];
    for (i = 0; i < n; ++i) {
        ch = getchar();
        if (ch != '\n') ans += ch;
        else if (ch == '\n' && i == n - 1) break;
        else if (ch == '\n') --i;
    }
    for (i = 0; i < n; ++i) {
        s[i].arr += ans.substr(i, ans.size());
        s[i].arr += ans.substr(0, i);
        s[i].space = i;
    }
    Str minstr = s[0];
    for (i = 0; i < n; ++i) if (s[i].arr < minstr.arr) minstr = s[i];
    cout << minstr.space;
    return 0;
}

94 求字符串的起始位置

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
int sub(char s[], char subs[])
{
	int j=0;
	int stop = 0,len1=strlen(s),len2=strlen(subs);
	for (int i = 0; i <=len1 - len2; i++)
	{
		if (s[i] == subs[j])
		{
			stop = i+1;
			for (j=j+1; j < len2; )
			{
				if (s[stop++] != subs[j++])
				{
					j = 0;
					break;
				}
			}
			if (j == len2)
			{
				return ++i;
			}
		}
	}
	return 0;
}
int main()
{
	char s[100], subs[100];
	int m = 0, i, j;
	while (cin >> s)
	{
		cin >> subs;
		m = 0;
		int stop=0;
		m = sub(s, subs);
		cout << m << endl;
	}

	return 0;
}

95 最长的单词

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
void maxs(char s[])
{
	int max = 0,maxi=0,count=0,j,i;
	for (j = 0; s[j] != ' '&&j<strlen(s); j++);
	max = j;
	maxi = j-1;
	//cout << max<<" "<<maxi<<endl;
	//cout << strlen(s) << endl;
	for (i=max+1; i < strlen(s); i++)
	{
		if (s[i] == ' ')
		{
			if (max < count)
			{
				max = count;
				maxi = i-1;
			}
			count = 0;
		}
		else if (i == (strlen(s) - 1))
		{
			count++;
			if (max < count)
			{
				max = count;
				maxi = i;
				count = 0;
			}
		}
		else
		{
			count++;
		}
	}
	cout << max << " ";
	for (int j = maxi - max+1; j <=maxi; j++)
	{
		cout << s[j];
	}
	cout << endl;
}
int main()
{
	char s[1000];
	
	while (gets(s))
	{
		maxs(s);

	}

	return 0;
}

96 奖学金

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
#include <cstring>
#include<string>
#include <stdio.h>
using namespace std;
typedef struct student
{
	char name[22];
	int a;//成绩
	int b;//班级评估
	char ganbu;
	char xibu;
	int lunwen;
	int money;
}student;
int main()
{
	int n, i,sum=0;//sum 总金额
	student* stu;
	while (cin >> n)
	{
		sum = 0;	
		stu = (student*)malloc(sizeof(student) * n);
		for (i = 0; i < n; i++)
		{
			cin >> stu[i].name;	
			cin>> stu[i].a >> stu[i].b >> stu[i].ganbu >> stu[i].xibu >> stu[i].lunwen;
			stu[i].money = 0;
			if (stu[i].a > 80 && stu[i].lunwen > 0)
				stu[i].money += 8000;
			if (stu[i].a > 85 && stu[i].b > 80)
				stu[i].money += 4000;
			if (stu[i].a > 90)
				stu[i].money += 2000;
			if (stu[i].a > 85 && stu[i].xibu == 'Y')
				stu[i].money += 1000;
			if (stu[i].b > 80 && stu[i].ganbu == 'Y')
				stu[i].money += 850;
			sum += stu[i].money;
		}
		int maxIndex = 0;
		for (i = 0; i < n; i++) {
			if (stu[i].money > stu[maxIndex].money)
				maxIndex = i;
		}
		//cout << maxIndex << endl;
		cout << stu[maxIndex].name << endl;
		cout << stu[maxIndex].money << endl;
		cout << sum << endl;
		cout << endl;
	}
	return 0;
}

97 回文数2

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long transtwo(int a)
{
	int t[1000],i=0;
	while (a)
	{
		t[i++] = a % 2;
		a /= 2;
	}
	long b = 0;
	for (int j = i - 1; j >= 0; j--)
	{
		b *= 10; 
		b += t[j];
	}
	return b;
}

bool isok(long long int a)
{
	int t[10000],i=0;
	while (a)
	{
		t[i++] = a % 10;
		a /= 10;
	}
	if (i == 1) return true;
	for (int j = 0; j < i/2; j++)
	{
		if (t[j] != t[i - j - 1]) return false;

	}
	return true;
}
int main()
{
	int n;
	while (cin >> n )
	{
		int f = 0;
		if (isok)f++;
		if (isok(transtwo(n)))f++;
		if (f < 2)cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	return 0;
}

98 加法器

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	char a[100000];
	while (gets(a))
	{
		long sum = 0;
		n = 0;
		for (int i = 0; i < strlen(a); i++)
		{
			if (a[i] != '+')
			{
				n *= 10;
				n += a[i]-'0';
			}
			else 
			{
				sum += n;
				n = 0;
			}
		}
		sum += n;
		cout << sum << endl;
	}
	return 0;
}

99 构造序列

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef struct linknode
{
	int date;
	struct linknode* next;
}linknode,*list;
void printxulie(int n)
{
	if (n<=4)
	{
		cout << 1;
		for (int i = n; i >= 2; i--)
		{
			cout << i;
		}
		for (int i = 3; i <= n; i++)
		{
			cout << i;
		}
		cout << 1 << endl;
	}
	else
	{
		char a[100] = { '1','4','3','2','3','4','1' };
		int count = 0;
		for (int j = 5; j <= n; j++)
		{
			for (int i = 0; i <7+count; i++)
			{
				if (a[i] - '0' + a[i + 1] - '0' == j)
				{
					
					for (int k = strlen(a) + count; k > i + 1; k--)
					{
						a[k] = a[k - 1];
					}
					count++;
					a[i + 1] = j + '0';
					i++;
				}
			}
		}
		for (int i = 0; i < strlen(a); i++)
		{
			cout << a[i];
		}
		cout << endl;
	}
}
int main()
{
	int n;
	while (cin>>n)
	{
		printxulie(n);
	}
	return 0;
}

100 纯粹合数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

bool isok1(int n)
{
	int j = n / 2;
	for (int i = 2; i <= j; i++)
	{
		if (n%i==0)return true;
	}
	return false;
}
bool isheshu(int n)
{
	int a[100],i=0,j=n,k,t;
	while (j)
	{
		a[i++] = j % 10;
		j /= 10;
	}
	for (int m=0;m<i-1;)
	{
		t = 0;
		while (a[i - 2 - m] == 0)m++;
		if (m == i - 1)break;
		for (int k = i -2-m; k >= 0;k-- )
		{
			t *= 10;
			t += a[k];
		}
		if (isok1(t))m++;
		else
		{
			return false;
		}
	}
	return true;
}
int main()
{
	int n;
	while (cin >> n)
	{
		int i = 1,j;
		if (n == 1)cout << 100 << endl;
		else {
			for (j = 101; i < n; j++)
			{
				if (isok1(j))
				{
					if (isheshu(j))
					{
						i++;
						if (i == n)break;
					}
				}
			}
			cout << j << endl;
		}
	}
	return 0;
}

101 找出质数

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
using namespace std;
int zicount(int num)
{
    if (num == 0 && num == 1) return 0;
    for (int i = 2; i <= sqrt(num); i++)
    {
        if (num % i == 0)
            return 0;
    }
    return 1;
}

int main()
{
    string s;
    int num, count, max=0;
    while (cin >> s)
    {
        int sum, max = -1;
        for (int i = 0; i < s.size(); i++)
        {
            sum = 0;
            count = 0;
            num = s[i] - '0';
            while (count < 4 && i < s.size())
            {
                sum = sum * 10 + num;
                if (zicount(sum) && sum > max)
                    max = sum;
                count++;
                i++;
                num = s[i] - '0';
            }
            i = i - count;
        }
        cout << max << endl;
    }
}

102 翻译字符串

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[20];
	while (gets(a))
	{
		int count = 0,j;
		for (int i = 0; i < strlen(a); i++)
		{
			if (a[i] >= 'a' && a[i] <= 'z')
			{
				if (count == 3)
				{
					cout << " ";
					count = 0;
				}
				cout << a[i];
				count++;
			}
			else if (a[i] >= '0' && a[i] <= '9')
			{
				j = i + 1;
				if (j < strlen(a))
				{
					for (int k = 0; k <=a[i] - '0'; k++)
					{
						if (count == 3)
						{
							cout << " ";
							count = 0;
						}
						cout << a[j];
						count++;
					}
				}
				i = j;
			}
			else if (a[i] == '@')
			{
				cout << a[i] ;
				break;
			}
		}
	cout << endl;
	}
	return 0;
}
  • 23
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值