当前位置:网站首页>天梯赛练习集题解LV1(all)

天梯赛练习集题解LV1(all)

2022-07-06 09:14:00 %xiao Q

L1-001 Hello World (5 分)

一道简单题

#include <stdio.h>
int main()
{
    
    printf("Hello World!\n");
    return 0;
}

L1-002 打印沙漏 (20 分)

这道题主要有3个坑点

  1. 无多余符号,0也要输出
  2. 符号之后的空格不需要填充,否则会报格式错误,但是符号之前的空格还是要打印的

参考代码:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    
	int n;
	char ch;
	cin >> n >> ch;
	
	int x = sqrt((n + 1) / 2); //计算有多少层 
	
	//输出倒三角 
	for(int i = 1; i <= x; i++)
	{
    
		for(int j = 1; j < i; j++) cout << ' ';
		for(int j = 0; j < 2 * (x - i + 1) - 1; j++) cout << ch;
		cout << endl;
	}
	
	//输出整三角 
	for(int i = 2; i <= x; i++)
	{
    
		for(int j = 0; j < x - i; j++) cout << ' ';
		for(int j = 0; j < 2 * i - 1; j++) cout << ch;
		cout << endl;
	}
	
	int ans = n - 2 * x * x + 1;
	cout << ans << endl; // 无多余符号,0也要输出 
	return 0;
}    

L1-003 个位数统计 (15 分)

这题数据范围不大,所以直接用一个数组记录一下所有数出现的次数即可。
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

const int N = 1010;

int st[N];

int main()
{
    
	string s;
	cin >> s;
	
	for(int i = 0; i < s.size(); i++) st[s[i] - '0']++;
	
	for(int i = 0; i <= 1000; i++)
		if(st[i]) printf("%d:%d\n", i, st[i]);
	return 0;
}

L1-004 计算摄氏温度 (5 分)

按题意模拟即可

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	printf("Celsius = %d\n", 5 * (n - 32) / 9);
	return 0;
}

L1-005 考试座位号 (15 分)

这题可以用map进行哈希,先全部存入map中,然后直接找就可以了。
参考代码:

#include <iostream>
#include <unordered_map>
using namespace std;

unordered_map<int, pair<string, int>> mp;

int main()
{
    
	string s; 
	int n, m, T;
	cin >> T;
	
	for(int i = 0; i < T; i++) 
	{
    
		cin >> s >> n >> m;
		mp[n] = {
    s, m};
	}
	
	cin >> T;
	while(T--)
	{
    
		cin >> n;
		cout << mp[n].first << ' ' << mp[n].second << endl;
	}
	
	return 0;
}

L1-006 连续因子 (20 分)

这题要求的是最长连续因子的个数,并输出最小的连续因子序列。
所以什么可以暴力枚举,那么要怎么枚举呢?
首先由数据范围可知,最大的长度不会大于10,所以我们枚举长度(从大到小),然后在开始枚举连续因子的第一个数,然后我们在判断在这个长度和这个数开始,能否成立,如果成立,那么就是我们需要的结果。
参考代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	int maxn = sqrt(n);
	for(int len = 10; len >= 1; len--)
		for(int start = 2; start <= maxn; start++) //小于maxn的是因为,sqrt(n) * (sqrt(n) + 1)大于n
		{
    
			int t = 1;
			for(int i = start; i <= start + len - 1; i++)
				t *= i;
				
			if(n % t == 0)
			{
    
				printf("%d\n%d", len, start);
				for(int i = start + 1; i <= start + len - 1; i++)
					printf("*%d", i);
				return 0;
			}
			
		}
	
	printf("1\n%d", n);
	return 0;
}

L1-007 念数字 (10 分)

一道简单题,直接在代码
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

string st[] = {
    "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};

int main()
{
    
	string s;
	cin >> s;
	
	for(int i = 0; i < s.size(); i++)
	{
    
		if(s[i] == '-') cout << "fu";
		else cout << st[s[i] - '0'];
		if(i != s.size() - 1) cout << ' '; //控制最后一个的空格
	}
	
	cout << endl;
	return 0;
}

L1-008 求整数段和 (10 分)

直接按题意模拟即可
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int a, b, sum = 0, t = 0;
	
	cin >> a >> b;
	for(int i = a; i <= b; i++)
	{
    
		sum += i;
		t++;
		printf("%5d", i);
		if(t == 5)
		{
    
			t = 0;
			printf("\n");
		}
	}
	
	if(t != 0) printf("\n");
	printf("Sum = %d\n", sum);
	
	return 0;
}

L1-009 N个数求和 (20 分)

这道题挺坑的,首先你得处理好你得输出,然后你得把他们相加。
处理输入的话,这里,我们直接两个数组来存,a数组存分子,b数组存分母,
然后把每个依次相加,相加的话,直接通分相加,然后在约分。
参考代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int ans1 = 0, ans2 = 0;

void slove(int a, int b)
{
    
    // 这里特判第一个
	if(!ans1 && !ans2)
	{
    
		ans1 = a, ans2 = b;
		return ;
	}
	
    // 通分并且相加
	int x2 = ans2 * b;
	int x1 = ans1 * b + a * ans2;
	
    // 约分
	int t = __gcd(x1, x2); //求出最大公约数
	ans1 = x1 / t, ans2 = x2 / t;
	
}

int main()
{
    
	int n;
	string s;
	cin >> n;
	
	while(n--)
	{
    
		int a = 0, b = 0;
		cin >> s;
		
		int t = 0;
		bool flag = false; //用于后面判断负号
		for(int i = 0; i < s.size(); i++)
		{
    
			if(s[i] == '-') flag = true;
			else if(s[i] == '/')
			{
    
				if(flag) a = t * -1;
				else a = t;
				
				flag = false;
				t = 0;
			}
			
			else
				t = t * 10 + s[i] - '0';
		}
		
		if(flag) b = t * -1;
		else b = t;
		
		slove(a, b);
	}
	
	if(ans2 == 1) cout << ans1 << endl;
	else 
	{
    
		if(ans1 / ans2) cout << ans1 / ans2 << ' ';
		cout << ans1 - ans2 * (ans1 / ans2) << '/' << ans2 << endl;
	}
	return 0;
}

L1-010 比较大小 (10 分)

这题比较简单,我就直接放代码了。
参考代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int a[3];

int main()
{
    
	cin >> a[0] >> a[1] >> a[2];
	
	sort(a, a + 3); // 排序
	printf("%d->%d->%d\n", a[0], a[1], a[2]);
	return 0;
} 

L1-011 A-B (20 分)

先把B字符串用map标记一下,然后遍历A串即可,遍历的途中判断是否输出。

#include <iostream>
#include <cstdio>
#include <unordered_map>
using namespace std;

unordered_map<char, int> mp;

int main()
{
    
	string s1, s2;
	getline(cin, s1); //读入一整行,可以读入空格,遇到回车结束
	getline(cin, s2);
	
	for(int i = 0; i < s2.size(); i++)
		mp[s2[i]] = 1;
	
	for(int i = 0; i < s1.size(); i++)
		if(!mp.count(s1[i])) cout << s1[i];
	puts("");
	return 0;
}

L1-012 计算指数 (5 分)

一道水题

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	printf("2^%d = %d\n", n, 1 << n);  // 1 << n = 2 ^ n
	return 0;
}

L1-013 计算阶乘和 (10 分)

直接2层循环解决问题。

#include <iostream>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	int ans = 0;
	for(int i = 1; i<= n; i++)
	{
    
		int sum = 1;
		for(int j = 1; j <= i; j++)
			sum *= j;
		ans += sum;
	}
	
	cout << ans << endl;
	return 0;
}

L1-014 简单题 (5 分)

大水题

#include <iostream>
using namespace std;

int main()
{
    
	cout << "This is a simple problem." << endl;
	return 0;
}

L1-015 跟奥巴马一起画方块 (15 分)

直接上代码。
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n;
	char ch;
	cin >> n >> ch;
	
    // 进行四舍五入
	int m = (n + 1) / 2;
	
	for(int i = 0; i < m; i++)
	{
    
		for(int j = 0; j < n; j++)
			cout << ch;
		cout << endl;
	}
	
	return 0;
}

L1-016 查验身份证 (15 分)

直接上代码:

#include <iostream>
#include <cstdio>

using namespace std;

int w[] = {
    7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; //存对应的权值
char st[] = {
    '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}; //存对应的校验码

int main()
{
    
	int n;
	cin >> n;
	string s;
	
	int t = 0;
	for(int i = 0; i < n; i++)
	{
    
		cin >> s;
		int sum = 0;
		bool flag = true;
		for(int i = 0; i < s.size() - 1; i++)
		{
    
			if(s[i] >= '0' && s[i] <= '9')
				sum += w[i] * (s[i] - '0');
			else
			{
    
				flag = false;
				break;
			}
		}
		
		char p = st[sum % 11];
		if(!flag || p != s[s.size() - 1]) 
		{
    
			cout << s << endl;
			t++;
		}
	}
	
	if(t == 0) puts("All passed");
	return 0;
}

L1-017 到底有多二 (15 分)

参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	string s;
	cin >> s;
	
	int cnt = 0;
	for(int i = 0; i < s.size(); i++)
		if(s[i] == '2') cnt++;
	
	int n = s.size();
	if(s[0] == '-') n--;
	double ans = 1.0 * cnt / n;
	
	if(s[0] == '-') ans *= 1.5;
	int t = s[s.size() - 1] - '0';
	
	if(t % 2 == 0) ans *= 2;
	
	printf("%.2f%\n", ans * 100);
	return 0;
}

L1-018 大笨钟 (10 分)

参考代码:

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    
	int a, b;
	scanf("%d:%d", &a, &b);
	
	if(a >= 0 && a <= 11 || a == 12 && b == 0)
		printf("Only %02d:%02d. Too early to Dang.", a, b); // %02d:不足两位补零
	else
	{
    
		a -= 12;
		string s = "Dang";
		if(b > 0) a++;
		for(int i = 0; i < a; i++) cout << s;
		puts("");
	}
	 
	return 0;
}

L1-019 谁先倒 (15 分)

参考代码:

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    
	int n, A, B;
	int a, b, c, d;
	cin >> A >> B >> n;
	
	int cnt_a = 0, cnt_b = 0;
	for(int i = 0; i < n; i++)
	{
    
		cin >> a >> b >> c >> d;
		
		if(b == d) continue; //俩个人划的相同,不可能定输赢,直接进行下一次的循环
		int t = a + c;
		
		if(t == b) cnt_a++; // a罚一杯
		else if(t == d) cnt_b++; // b罚一杯
		
        // a倒了
		if(cnt_a > A)
		{
    
			cout << "A" << endl;
			cout << cnt_b << endl;;
			break;
		}
		
        // b倒了
		if(cnt_b > B)
		{
    
			cout << "B" << endl;
			cout << cnt_a << endl;
			break;
		}
	}
	
	return 0;
}

L1-020 帅到没朋友 (20 分)

这题可以直接用map做标记,然后在查询的过程中,也用map做标记,防止重复输出2个相同的人。
参考代码:

#include <iostream>
#include <cstdio>
#include <unordered_map>
using namespace std;

unordered_map<string, int> mp;
unordered_map<string, int> st;

int main()
{
    
	int T;
	cin >> T;
	
	while(T--)
	{
    
		int n;
		cin >> n;
		
		string s;
		for(int i = 0; i < n; i++)
		{
    
			cin >> s;
			if(n > 1) mp[s]++;
		}
	}
	
	cin >> T;
	int t = 0;
	while(T--)
	{
    
		string s;
		cin >> s;
		
		if(st.count(s)) continue;
		st[s]++;
		if(!mp.count(s))
		{
    
			if(t != 0) cout << ' ';
			t++;
			cout << s;
		}
	}
	
	if(t == 0) printf("No one is handsome");
	puts("");
	
	return 0;
}

L1-021 重要的话说三遍 (5 分)

直接上代码:

#include <iostream>
using namespace std;

int main()
{
    
	for(int i = 0; i < 3; i++)
		cout << "I'm gonna WIN!" << endl;
	return 0;
}

L1-022 奇偶分家 (10 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	int t1 = 0, t2 = 0;
	for(int i = 0; i < n; i++)
	{
    
		int x;
		cin >> x;
		if(x % 2) t1++;
		else t2++;
	}
	
	cout << t1 << ' ' << t2 << endl;
	return 0;
}

L1-023 输出GPLT (20 分)

可以用1个数组存下4字母的数量,然后在按“GPLT”的顺序进行输出即可
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

int a[4];

int main()
{
    
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++)
	{
    
		if(s[i] == 'G' || s[i] == 'g') a[0]++;
		else if(s[i] == 'P' || s[i] == 'p') a[1]++;
		else if(s[i] == 'L' || s[i] == 'l') a[2]++;
		else if(s[i] == 'T' || s[i] == 't') a[3]++;
	}
	
	while(a[0] || a[1] || a[2] || a[3])
	{
    
		if(a[0])
		{
    
			cout << 'G';
			a[0]--;
		}
		
		if(a[1])
		{
    
			cout << 'P';
			a[1]--;
		}
		
		if(a[2])
		{
    
			cout << 'L';
			a[2]--;
		}
		
		if(a[3])
		{
    
			cout << 'T';
			a[3]--;
		}
	}
	
	cout << endl;
	return 0;
}

L1-024 后天 (5 分)

直接上代码:

#include <iostream>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	int ans = (n + 2) % 7;
	
	if(ans == 0) cout << 7 << endl; // 为0时既是星期天
	else cout << ans << endl;
	return 0;
}

L1-025 正整数A+B (15 分)

这题总的来说,有几点需要注意:

  1. 第一个空格为A,B的分隔
  2. A可能为空串
    所以我们可以直接一整行读进去,然后在进行分割,分成A,B,然后进行判断即可
    参考代码:
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	string s1, s2, s;
	getline(cin, s);
	
	bool flag = true;
	for(int i = 0; i < s.size(); i++)
	{
    
		if(flag && s[i] == ' ')
		{
    
			flag = false;
			continue;
		}
		if(flag) s1 += s[i];
		else s2 += s[i];
	}
	
// cout << s1 << endl << s2 << endl;
	
	bool flag1 = true, flag2 = true;
	for(int i = 0; i < s1.size(); i++)
		if(s1[i] < '0' || s1[i] > '9') flag1 = false;
		
	for(int i = 0; i < s2.size(); i++)
		if(s2[i] < '0' || s2[i] > '9') flag2 = false;
	
	if(s1.size() == 0) flag1 = false;	
	
	int t1 = 0, t2 = 0;
	if(flag1)
	{
    
		if(s1.size() > 4) 
		{
    
			cout << "?";
			flag1 = false;
		}
		else
		{
    
			for(int i = 0; i < s1.size(); i++)
				t1 = t1 * 10 + s1[i] - '0';
			if(t1 > 1000 || t1 == 0)
			{
    
				cout << "?";
				flag1 = false;
			}
			else cout << t1;
		}
	}
	else cout << "?";
	cout << " + ";
	
	if(flag2)
	{
    
		if(s2.size() > 4)
		{
    
			cout << "?";
			flag2 = false;
		}
		else
		{
    
			for(int i = 0; i < s2.size(); i++)
				t2 = t2 * 10 + s2[i] - '0';
			if(t2 > 1000 || t2 == 0)
			{
    
				cout << "?";
				flag2 = false;
			}
			else cout << t2;
		}
	}
	else cout << "?";
	cout << " = ";
	
	if(flag1 && flag2) cout << t1 + t2;
	else cout << "?";
	cout << endl;
	return 0;
}

L1-026 I Love GPLT (5 分)

直接上代码:

#include <iostream>
using namespace std;

int main()
{
    
	string s = "I Love GPLT";
	for(int i = 0; i < s.size(); i++)
		cout << s[i] << endl;
	return 0;
}

L1-027 出租 (20 分)

我们可以存下所有不同的数字,然后排序,然后在开一个数组存使其下标和值进行转换。
然后遍历电话号码即可。
参考代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

const int N = 200;

int ar[N];
int arr[N], n;
int index[N], m;
bool st[N];

bool cmp(int x, int y)
{
    
	return x > y;
}

int main()
{
    
	string s;
	cin >> s;
	
	for(int i = 0; i < s.size(); i++)
	{
    
		int t = s[i] - '0';
		if(!st[t])
			arr[n++] = t;
		st[t] = true;
	}
	
	sort(arr, arr + n, cmp); //排序
	
	printf("int[] arr = new int[]{%d", arr[0]);
	for(int i = 1; i < n; i++)
		printf(",%d", arr[i]);
	printf("};\n");
	
	// 交换下标和值
	for(int i = 0; i < n; i++)
	{
    
		int t = arr[i];
		ar[t] = i;
	}
	
	for(int i = 0; i < s.size(); i++)
	{
    
		int t = s[i] - '0';
		index[m++] = ar[t];
	}
	
	printf("int[] index = new int[]{%d", index[0]);
	for(int i = 1; i < m; i++)
		printf(",%d", index[i]);
	printf("};\n");
	
	return 0;
} 

L1-028 判断素数 (10 分)

直接用试除法去判断
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

bool judge(int x)
{
    
	if(x == 1) return false;
	for(int i = 2; i <= x / i; i++)
		if(x % i == 0) return false;
	return true;
}

int main()
{
    
	int T;
	cin >> T;
	
	while(T--)
	{
    
		int x;
		cin >> x;
		
		if(judge(x))
			puts("Yes");
		else puts("No");
	}
	
	return 0;
}

L1-029 是不是太胖了 (5 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int h;
	cin >> h;
	
	double ans = (h - 100) * 0.9 * 2;
	printf("%.1f\n", ans);
	return 0;
}

L1-030 一帮一 (15 分)

这题可以用2个数组存下男生和女生,然后在遍历所有的学生,并且去找与之配对的学生,
因为所有的学生是按排名顺序输入的,所以存的时候男生和女生也是按顺序来的,所以我们找配对的学生,可以直接在末尾找,找完得进行标记,防止重复配对。
参考代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_map>
using namespace std;

typedef pair<int, string> PIS;
const int N = 55;

PIS s[N];
vector<string> boy; //存男生
vector<string> girl; //存女生
unordered_map<string, int> st;

int main()
{
    
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
    
		int a; string b;
		cin >> a >> b;
		
		s[i] = {
    a, b};
		if(a == 0) girl.push_back(b);
		else boy.push_back(b);
	}
	
	int r1 = boy.size() - 1, r2 = girl.size() - 1;
	for(int i = 0; i < n; i++)
	{
    
		if(st.count(s[i].second)) continue;
		
		if(s[i].first == 0)
		{
    
			cout << s[i].second << ' ';
			cout << boy[r2] << endl;
			st[boy[r2]] = 1;
			r2--;
		}
		
		else
		{
    
			cout << s[i].second << ' ';
			cout << girl[r1] << endl;
			st[girl[r1]] = 1;
			r1--;	
		}
		
		st[s[i].second] = 1;
	}
	
	return 0;
}

L1-031 到底是不是太胖了 (10 分)

直接上代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    
	int T;
	cin >> T;
	
	while(T--)
	{
    
		int h, w;
		cin >> h >> w;
		
		double t = (h - 100) * 0.9 * 2;
		
		if(abs(w - t) < t * 0.1) puts("You are wan mei!");
		else if(w > t) puts("You are tai pang le!");
		else puts("You are tai shou le!");
	}
	
	return 0;
}

L1-032 Left-pad (20 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n;
	char ch;
	string s;
	cin >> n >> ch;
	getchar();
	getline(cin, s);
	
	if(n <= s.size())
		for(int i = s.size() - n; i < s.size(); i++)
			cout << s[i];
			
	else
	{
    
		for(int i = 0; i < n - s.size(); i++) cout << ch;
		for(int i = 0; i < s.size(); i++) cout << s[i]; 
	}
	
	puts("");
	return 0;
}

L1-033 出生年 (15 分)

这题需要注意,不同的数字正好是n位
参考代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int y, n;
bool st[10];

// 判断有几位数不同
bool judge(int x)
{
    
	memset(st, 0, sizeof st);
	int cnt = 0;
	
	for(int i = 0; i < 4; i++)
	{
    
		int t = x % 10;
		if(!st[t]) cnt++;
		st[t] = true; 
		x /= 10;
	}
	
	if(cnt == n) return true;
	return false;
}

int main()
{
    
	cin >> y >> n;
	
	int t = 0;
	for(int i = y; ; i++)
	{
    
		if(judge(i))
		{
    
			printf("%d %04d\n", t, i); //记得不足4位补零
			break;
		}
		else t++;
	}
	
	return 0;
}

L1-034 点赞 (20 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

const int N = 1010;

int a[N];

int main()
{
    
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
    
		int m;
		cin >> m;
		for(int j = 0; j < m; j++)
		{
    
			int x;
			cin >> x;
			a[x]++;
		}
	}
	
	int ans, maxn = -1;
	for(int i = 1; i <= 1000; i++)
	{
    
		if(a[i] >= maxn)
		{
    
			maxn = a[i];
			ans = i;
		}
	}
	
	cout << ans << ' ' << maxn << endl;
	return 0;
}

L1-035 情人节 (15 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

string a, b, s;

int main()
{
    	
	int t = 0;
	while(1)
	{
    
		cin >> s;
		if(s.size() == 1 && s[0] == '.') break;
		t++;
		
		if(t == 2) a = s;
		else if(t == 14) b = s;
	}
	
	if(t < 2) puts("Momo... No one is for you ...");
	else if(t < 14) cout << a << " is the only one for you..." << endl;
	else cout << a << " and " << b << " are inviting you to dinner...\n";
	return 0;
}

L1-036 A乘以B (5 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int a, b;
    cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

L1-037 A除以B (10 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int a, b;
	cin >> a >> b;
	
	if(b == 0)
	{
    
		printf("%d/%d=Error\n", a, b);
		return 0;
	}
	
	double ans = 1.0 * a / b;
	
	if(b > 0)
		printf("%d/%d=%.2f\n", a, b, ans);
	else
		printf("%d/(%d)=%.2f\n", a, b, ans); 
	return 0;
}

L1-038 新世界 (5 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	printf("Hello World\nHello New World\n");
	return 0;
}

L1-039 古风排版 (20 分)

直接上代码:

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    
	int n;
	string s;
	cin >> n; 
	getchar();
	getline(cin, s);
	
	int m = s.size();
	int t = ceil(1.0 * m / n); //向上取整,求出有几列 
	
	// 按题目意思进行输出 
	for(int i = 0; i < n; i++)
	{
    	
		for(int j = t - 1; j >= 0; j--)
		{
    
			int d = j * n + i;
			if(d >= s.size()) cout << ' ';
			else cout << s[d];
		}
		
		puts("");
	}
	
	return 0;
}

L1-040 最佳情侣身高差 (10 分)

直接上代码:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int T;
	cin >> T;
	
	while(T--)
	{
    
		double x;
		char ch;
		
		cin >> ch >> x;
		if(ch == 'F')
			printf("%.2f\n", x * 1.09);
		else
			printf("%.2f\n", x / 1.09);
	}
	
	return 0;
} 

L1-041 寻找250 (10 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int x, t = 0;
	while(cin >> x)
	{
    
		t++;
		if(x == 250)
		{
    
			cout << t << endl;
			break;
		}
	}
	
	return 0;
}

L1-042 日期格式化 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int a, b, c;
	scanf("%d-%d-%d", &a, &b, &c);
	
	printf("%04d-%02d-%02d\n", c, a, b);
	return 0;
}

L1-043 阅览室 (20 分)

/* 本题有3个点需要注意一下: 1. 如果借书,从最后的借书的时间开始 2. 书还完以后可能还为在借 3. 然后这里的平均数是四舍五入 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

const int N = 1010;

int st[N];
bool vis[N];

int main()
{
    
	int n;
	cin >> n;
	
	int t = 0, cnt = 0, ans = 0;
	while(1)
	{
    
		int id, a, b;
		char ch;
		scanf("%d %c %d:%d", &id, &ch, &a, &b);
		
		if(id == 0)
		{
    
			t++;
			
			double sum = 0;
			if(cnt != 0)
				sum = round(1.0 * ans / cnt); //进行四舍五入 
			cout << cnt << ' ' << sum << endl;
			memset(st, 0, sizeof st);
			memset(vis, 0, sizeof vis);
			cnt = ans = 0;
			
			if(t == n) break;
			continue;
		}
		
		if(ch == 'S')
		{
    
			st[id] = a * 60 + b;
			vis[id] = true;
		}
		else
		{
    
			if(vis[id])
			{
    
				cnt++;
				ans += a * 60 + b - st[id];
				vis[id] = false;
			}
		}
	}
	
	return 0;
}

L1-044 稳赢 (15 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int t;
	cin >> t;
	
	int cnt = 0;
	while(1)
	{
    
		string s;
		cin >> s;
		
		if(s == "End") break;
		if(cnt == t)
		{
    
			cout << s << endl;
			cnt = 0;
		}
		else
		{
    
			cnt++;
			if(s == "ChuiZi") puts("Bu");
			else if(s == "JianDao") puts("ChuiZi");
			else puts("JianDao");
		}
	}
	
	return 0;
} 

L1-045 宇宙无敌大招呼 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	string s;
	cin >> s;
	cout << "Hello " << s << endl;
	return 0;
}

L1-046 整除光棍 (20 分)

/* 思路: 这题可以用除法原理来求解,我们可以另t = 1, 然后在除以x,在用起余数即,t % x来乘10 + 1, 当然这里得注意前导零。 */
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int x;
	cin >> x;
	
	int t = 1, len = 1;
	bool flag = false;
	while(1)
	{
    
		if(t / x != 0) flag = true; //防止输出前导零
		if(flag) cout << t / x;
		
		if(t % x == 0) break;
		t %= x;
		t = t * 10 + 1;
		len++;
	}
	
	cout << ' ' << len << endl;
	return 0;
}

L1-047 装睡 (10 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	while(n--)
	{
    
		string s;
		int a, b;
		cin >> s >> a >> b;
// cout << s << ' ' << a << ' ' << b;
		
		if(a < 15 || a > 20 || b < 50 || b > 70) cout << s << endl;
	} 
	
	return 0;
} 

L1-048 矩阵A乘以B (15 分)

#include <iostream>
#include <cstdio>
using namespace std;

const int N = 110;

int a[N][N], b[N][N], ans[N][N];

int main()
{
    
	int ra, ca, rb, cb;
	cin >> ra >> ca;
	for(int i = 0; i < ra; i++)
		for(int j = 0; j < ca; j++) cin >> a[i][j];
	
	cin >> rb >> cb;
	for(int i = 0; i < rb; i++)
		for(int j = 0; j < cb; j++) cin >> b[i][j];
	
	if(ca != rb) printf("Error: %d != %d\n", ca, rb);
	else
	{
    
		cout << ra << ' ' << cb << endl;
		
		for(int i = 0; i < ra; i++)
		{
    
			for(int j = 0; j < cb; j++)
			{
    
				int sum = 0;
				for(int k = 0; k < ca; k++) sum += a[i][k] * b[k][j];
				if(j != 0) cout << ' ';
				cout << sum;
			}
			
			puts("");
		}
	}
	
	return 0;
}

L1-049 天梯赛座位分配 (20 分)

/* 本题有一点需要注意: 那就是如果只有一个队伍的话,号码是从1开始,若测试点2错误,考虑一下一个队伍的情况 */
#include <iostream>
#include <cstdio>
#include <vector> 
using namespace std;

const int N = 110;

int a[N];
bool st[N];
vector<int> ans[N];

int main()
{
    
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int t = 0, cnt = 0;
	if(n == 1) t = -1; //特判一个队伍的情况 
	while(1)
	{
    
		if(cnt == n) break;
		for(int i = 0; i < n; i++)
		{
    
			if(st[i]) continue;
			if(ans[i].size() + 1 > a[i] * 10)
			{
    
				cnt++;
				st[i] = true;
				continue;
			}
			
			if(cnt == n - 1)
			{
    
				ans[i].push_back(t + 2);
				t += 2;
			}
			else ans[i].push_back(++t);
		}
	}
	
	for(int i = 0; i < n; i++)
	{
    
		printf("#%d\n", i + 1);
		int t = 0;
		for(int j = 0; j < ans[i].size(); j++)
		{
    
			t++;
			if(t == 10)
			{
    
				t = 0;
				cout << ans[i][j] << endl;
			}
			else cout << ans[i][j] << ' ';
		}
		
	}
	
	return 0;
}

L1-050 倒数第N个字符串 (15 分)

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int m = 0;
char s[15];

int main()
{
    
	int L, n;
	cin >> L >> n;
	
	int t = pow(26, L) - n; //求出正数第几位 
	
	while(t)
	{
    
		int x = t % 26;
		s[m++] = 'a' + x;
		t /= 26;
	}
	
	// 当字符串不足L位,要记得补前导 'a' 
	if(m < L) 
	{
    
		for(int i = 0; i < L - m; i++) cout << 'a';
	}
	for(int i = m - 1; i >= 0; i--) cout << s[i];
	cout << endl;
	return 0;
}

L1-051 打折 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int n, m;
	cin >> n >> m;
	double ans = n * m / 10.0;
	
	printf("%.2f\n", ans);
	return 0;
} 

L1-052 2018我们要赢 (5 分)

PHP(世界上最好的语言,狗头)

2018
wo3 men2 yao4 ying2 !

L1-053 电子汪 (10 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int a, b;
	cin >> a >> b;
	
	for(int i = 0; i < a + b; i++) cout << "Wang!";
	cout << endl;
	return 0;
}

L1-054 福到了 (15 分)

/* 本题的注意事项: 本题的翻转是左右,上下都要翻转 */
#include <iostream>
#include <cstdio>
using namespace std;

const int N = 110;

int n;
char ch;
string s[N];

int main()
{
    
	cin >> ch >> n;
	getchar();
	for(int i = 0; i < n; i++) getline(cin, s[i]);
	
	/*判断左右是否对称,但是我发现数据比较水,没有进行上下判断也得了满分(但是出于题解的正确性, 还是给出了上下的判断) */ 
	bool flag = true;
	for(int i = 0; i < n; i++)
	{
    
		int l = 0, r = s[i].size() - 1;
		while(l < r)
		{
    
			if(s[i][l] != s[i][r]) 
			{
    
				flag = false;
				break;
			}
			
			l++, r--;
		}
		
		if(!flag) break;
	}
	
	// 判断上下是否对称 
	bool flag0 = true;
	if(flag) //如果左右不对称,那么就没必要判断上下是否对称 
	{
    
		for(int i = 0; i < n; i++)
		{
    
			int l = 0, r = n - 1;
			while(l < r)
			{
    
				if(s[l][i] != s[r][i]) 
				{
    
					flag0 = false;
					break;
				}
				
				l++, r--;
			}
			
			if(!flag0) break;
		}
	} 
	
	if(!flag || !flag0)
	{
    
		for(int i = 0; i < n; i++)
		{
    
			int l = 0, r = s[i].size() - 1;
			while(l < r)
			{
    
				swap(s[i][l], s[i][r]);
				l++, r--;
			}
		}
	}
	
	else puts("bu yong dao le");
	
	for(int i = n - 1; i >= 0; i--)
	{
    
		for(int j = 0; j < s[i].size(); j++)
			if(s[i][j] != ' ') cout << ch;
			else cout << s[i][j];
		puts("");
	}
	
	return 0;
}

L1-055 谁是赢家 (10 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int pa, pb;
	cin >> pa >> pb;
	
	int a = 0, b = 0;
	for(int i = 0; i < 3; i++)
	{
    
		int  x;
		cin >> x;
		
		if(!x) a++;
		else b++;
	}
	
	if(pa > pb) 
	{
    
		if(b == 3) printf("The winner is b: %d + %d\n", pb, b);
		else printf("The winner is a: %d + %d\n", pa, a);
	}
	
	else
	{
    
		if(a == 3) printf("The winner is a: %d + %d\n", pa, a);
		else printf("The winner is b: %d + %d\n", pb, b);
	}
	
	
	return 0;
} 

L1-056 猜数字 (20 分)

#include <iostream>
#include <cstdio>
using namespace std;

const int N = 1e4 + 10;
typedef pair<string, int> PSI; //可以百度一下pair的用法,挺好用的

int n;
PSI a[N];

int main()
{
    
	cin >> n;
	
	int sum = 0;
	for(int i = 0; i < n; i++)
	{
    
		string s;
		int x;
		cin >> s >> x;
		
		sum += x;
		a[i] = {
    s, x};
	}
	
	int avg = sum / n / 2;
	
    // 寻找最接近avg的数,并记录下标
	int t = -1, minn = 2e9;
	for(int i = 0; i < n; i++)
	{
    
		int d = abs(a[i].second - avg);
		if(d < minn)
		{
    
			t = i;
			minn = d;
		}
	}
	
	cout << avg << ' ' << a[t].first << endl;
	return 0;
}

L1-057 PTA使我精神焕发 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	printf("PTA shi3 wo3 jing1 shen2 huan4 fa1 !\n");
	return 0;
}

L1-058 6翻了 (15 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	string s;
	getline(cin, s);
	
	for(int i = 0; i < s.size(); i++)
	{
    
		if(s[i] != '6') cout << s[i];
		else
		{
    
			int j = i;
			while(s[j] == '6') j++;
			
			if(j - i > 9) cout << 27;
			else if(j - i > 3) cout << 9;
			else
				for(int k = 0; k < j - i; k++) cout << 6;
			i = j - 1;
		}
	}
	
	puts("");
	return 0;
}

L1-059 敲笨钟 (20 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int T;
	cin >> T;
	getchar();
	
	while(T--)
	{
    
		string s;
		getline(cin, s);
		
        //判断是否押韵
		bool flag1 = false, flag2 = false;
		for(int i = 0; i < s.size(); i++)
		{
    
			if(s[i] == ',' && s[i - 3] == 'o' && s[i - 2] == 'n' && s[i - 1] == 'g') flag1 = true; 
			if(s[i] == '.' && s[i - 3] == 'o' && s[i - 2] == 'n' && s[i - 1] == 'g') flag2 = true; 
		}
		
		if(flag1 && flag2)
		{
    
            //找到3个空格(即3单词)
			int t = 0, idx;
			for(int i = s.size() - 1; i >= 2; i--)
			{
    
				if(s[i] == ' ') t++;
				if(t == 3)
				{
    
					idx = i;
					break;
				}
			}
			
			for(int i = 0; i <= idx; i++) cout << s[i];
			cout << "qiao ben zhong.\n";
		}
		
		else puts("Skipped");
	}
	
	return 0;
}

L1-060 心理阴影面积 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int x, y;
	cin >> x >> y;
	
	int ans = 5000 - 0.5 * x * y - 0.5 * (100 - x) * (100 - y) - (100 - x) * y;
	cout << ans << endl;
	return 0;
}

L1-061 新胖子公式 (10 分)

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    
	double x, y;
	cin >> x >> y;
	
	double ans = x / (pow(y, 2));
	
	printf("%.1f\n", ans);
	if(ans > 25) puts("PANG");
	else puts("Hai Xing");
	
	return 0;
} 

L1-062 幸运彩票 (15 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int T;
	cin >> T;
	
	while(T--)
	{
    
		string s;
		cin >> s;
		
		int sum1 = 0, sum2 = 0;
		for(int i = 0; i < 3; i++) sum1 += s[i] - '0';
		for(int i = 3; i < 6; i++) sum2 += s[i] - '0';
		
		if(sum1 == sum2) puts("You are lucky!");
		else puts("Wish you good luck."); 
	} 
	
	return 0;
}

L1-063 吃鱼还是吃肉 (10 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int T;
	cin >> T;
	
	while(T--)
	{
    
		int sex, h, w;
		cin >> sex >> h >> w;
		
		if(sex)
		{
    
			if(h < 130) cout << "duo chi yu!";
			else if(h > 130) cout << "ni li hai!";
			else cout << "wan mei!";
				
			if(w < 27) cout << " duo chi rou!";
			else if(w > 27) cout << " shao chi rou!";
			else cout << " wan mei!";
			
			cout << endl;
		}
		
		else
		{
    
			if(h < 129) cout << "duo chi yu!";
			else if(h > 129) cout << "ni li hai!";
			else cout << "wan mei!";
			
			if(w < 25) cout << " duo chi rou!";
			else if(w > 25) cout << " shao chi rou!";
			else cout << " wan mei!";
			
			cout << endl;
		}
	}
	
	return 0;
}

L1-064 估值一亿的AI核心代码 (20 分)

因本人代码未得满分,贴一下@ssf_cxdm博主的代码,(这题好难调呀)

#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<cstdio>
using namespace std;

int main(){
    
    int n;
    scanf("%d",&n);
    //别忘了这句
    getchar();
    while(n--){
    
        string s,str[1005],s1;
        int cnt=0;
        getline(cin,s);
        cout<<s<<endl;
        cout<<"AI:";
        for(int i=0;i<s.size();i++){
    
            if(isalnum(s[i])){
      //isalnum(),字母或数字
                if(s[i]!='I')
                    s[i]=tolower(s[i]);  //tolower()
            }else{
    
                //分割成一块一块的
                s.insert(i," ");  //s.insert()
                 i++;
            }
            if(s[i]=='?')
                s[i]='!';
        }
        stringstream ss(s);  //消除空格
        while(ss>>s1){
    
            str[cnt++]=s1;
        }
        if(!isalnum(str[0][0]))
            cout<<" ";
        for(int i=0;i<cnt;i++){
    
            if(!isalnum(str[i][0])){
     //标点符号前不存在空格
                cout<<str[i];
            }
            else if(str[i]=="can"&&(i+1<cnt&&str[i+1]=="you")){
    
                cout<<" I can";
                i++;
            }
            else if(str[i]=="could"&&(i+1<cnt&&str[i+1]=="you")){
    
                cout<<" I could";
                i++;
            }
            else if(str[i]=="I"||str[i]=="me"){
    
                cout<<" you";
            }
            else cout<<" "<<str[i];  //第一个字符为字母或数字,前面得加一个空格
        }
        cout<<endl;
    }

    return 0;
}

L1-065 嫑废话上代码 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	cout << "Talk is cheap. Show me the code." << endl;
	return 0;
}

L1-066 猫是液体 (5 分)

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    
	int a, b, c;
	cin >> a >> b >> c;
	
	cout << a * b * c << endl;
	return 0;
}

L1-067 洛希极限 (10 分)

#include <iostream>
#include <cstdio>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	double a, b, c;
	cin >> a >> b >> c;
	
	if(b) a *= 1.26;
	else a *= 2.455;
	
	if(a < c)
		printf("%.2f ^_^\n", a);
	else 
		printf("%.2f T_T\n", a);
	return 0;
}

L1-068 调和平均 (10 分)

//一道好傻逼的题目, 语文理解了属于是,好好理解一下:它们的调和平均是它们倒数的算数平均的倒数 
#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	int n;
	cin >> n;
	
	double sum = 0;
	rep(i, 1, n)
	{
    
		double x;
		cin >> x;
		x = 1 / x;
		sum += x;
	}
	
	
	printf("%.2f\n", 1 / (sum / n));
	return 0;
} 

L1-069 胎压监测 (15 分)

#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int a[4];
//int ans[4];

int main()
{
    
	int x, y, maxn = -1;
	reps(i, 0, 4) 
	{
    
		cin >> a[i];
		maxn = max(maxn, a[i]);
	}
	cin >> x >> y;
	
	int t1 = 0, t2 = 0, ans1, ans2;
	reps(i, 0, 4)
	{
    
		if(a[i] < x)
		{
    
			t1++;
			ans1 = i + 1;
		}
		if(abs(a[i] - maxn) > y) 
		{
    
			t2++;
			ans2 = i + 1;
		}
	}
	
	if(t1 == 0 && t2 == 0) puts("Normal");
	else if(t1 == 1 && t2 == 0) printf("Warning: please check #%d!\n", ans1);
	else if(t1 == 0 && t2 == 1) printf("Warning: please check #%d!\n", ans2);
	else if(t1 == 1 && t2 == 1 && ans1 == ans2) printf("Warning: please check #%d!\n", ans1);
	else puts("Warning: please check all the tires!");
	
	return 0; 
}

L1-070 吃火锅 (15 分)

#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	string s;
	int ans1 = 0, ans2, t = 0;
	bool flag = true;
	while(getline(cin, s))
	{
    
		if(s == ".") break;
		t++;
// cout << t << endl;
		if(s.find("chi1 huo3 guo1") != -1) ans1++;
		if(ans1 == 1 && flag) ans2 = t, flag = false;
	}
	
	cout << t << endl;
	if(ans1 == 0) puts("-_-#");
	else cout << ans2 << ' ' << ans1 << endl;
	
	return 0;
}

L1-071 前世档案 (20 分)

//这题可以尝试找一下规律,不过也可以先看一下满二叉树的规律 
#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	int n, m;
	cin >> n >> m;
	
	while(m--)
	{
    
		int t = n - 1;
		string s;
		cin >> s;
		
		int ans = 1;
		reps(i, 0, s.size())
		{
    
			if(s[i] == 'n') ans += 1 << t;
			t--;
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

L1-072 刮刮彩票 (20 分)

#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int st[] = {
    0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,306,1080,144,1800,3600};
int a[5][5];
bool vis[10];

int main()
{
    
	int x, y;
	rep(i, 1, 3) //宏定义,相当于1~3的循环,可以看上面的define,后面的题目可能都会出现,大家可以稍微了解一下
		rep(j, 1, 3)
		{
    
			cin >> a[i][j];
			if(a[i][j] == 0) x = i, y = j;
			vis[a[i][j]] = true;
		}
	rep(i, 1, 9) 
		if(!vis[i])
		{
    
			a[x][y] = i;
			break;
		}
		
	rep(i, 1, 3)
	{
    
		cin >> x >> y;
		cout << a[x][y] << endl;
	}
	
	int t, sum = 0;;
	cin >> t;
	if(t <= 3)
		rep(j, 1, 3) sum += a[t][j]; 
	
	else if(t <= 6)
		rep(i, 1, 3) sum += a[i][t - 3];
	else if(t == 7)
		sum = a[1][1] + a[2][2] + a[3][3];
	else sum = a[1][3] + a[2][2] + a[3][1];
	
	cout << st[sum] << endl;
	return 0;
} 

L1-073 人与神 (5 分)

#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	printf("To iterate is human, to recurse divine.\n");
	return 0;
}

L1-074 两小时学完C语言 (5 分)

#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	int a, b, c;
	cin >> a >> b >> c;
	cout << a - b * c << endl;
}

L1-075 强迫症 (10 分)

#include <cstdio>
#include <iostream>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main()
{
    
	string s;
	cin >> s;
	
	if(s.size() == 4)
	{
    
		int t = (s[0] - '0') * 10 + s[1] - '0';
		if(t < 22) printf("20%c%c-%c%c", s[0], s[1], s[2], s[3]);
		else  printf("19%c%c-%c%c", s[0], s[1], s[2], s[3]);
	}
	
	else
	{
    
		rep(i, 0, 3) printf("%c", s[i]);
		printf("-%c%c", s[4], s[5]);
	}
	
	return 0;
}

L1-076 降价提醒机器人 (10 分)

#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

vector<double> ans;

int main()
{
    
	int n, m;
	cin >> n >> m;
	
	while(n--)
	{
    
		double x;
		cin >> x;
		
		if(x < m) ans.push_back(x);
	}
	
	reps(i, 0, ans.size())
	{
    
// cout << i << endl;
		printf("On Sale! %.1f", ans[i]);
		if(i != ans.size() - 1) puts("");
	}
	
	return 0;
}

L1-077 大笨钟的心情 (15 分)

#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
using namespace std;

vector<int> b;
int a[24];

int main()
{
    
	reps(i, 0, 24) cin >> a[i];
	
	int t;
	while(cin >> t)
	{
    
		if(t < 0 || t > 23) break;
		b.push_back(t);
	}
	
	reps(i, 0, b.size())
	{
    
		printf("%d ", a[b[i]]);
		if(a[b[i]] > 50) cout << "Yes";
		else cout << "No";
		
		if(i != b.size() - 1) cout << endl;
	}
	
	return 0;
}

L1-078 吉老师的回归 (15 分)

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++) 
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;

int main()
{
    
	int n, m;
	cin >> n >> m;
	getchar();
	
// bool flag = false;
	while(n--)
	{
    
		string s;
		getline(cin, s);
		if(s.find("qiandao") != -1 || s.find("easy") != -1) continue;
		
		if(m == 0) 
		{
    
			cout << s;
			return 0;
		}
		m--;
	}
	
	if(m >= 0) cout << "Wo AK le";
	return 0;
}

L1-079 天梯赛的善良 (20 分)

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++) 
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;

const int N = 1e6 + 10;

int st[N];

int main()
{
    
	int n;
	cin >> n;
	
	int minn = 2e9, maxn = -1;
	rep(i, 1, n) 
	{
    
		int x;
		cin >> x;
		minn = min(minn, x);
		maxn = max(maxn, x);
		st[x]++;
	}
	
	cout << minn << ' ' << st[minn] << endl;
	cout << maxn << ' ' << st[maxn];
	return 0;
}

L1-080 乘法口诀数列 (20 分)

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++) 
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;

vector<int> a;

int main()
{
    
	int x, y, n;
	cin >> x >> y >> n;
	
	a.push_back(x); a.push_back(y);
	
	int i = 0, j = 1;
	while(a.size() <= n)
	{
    
		int t = a[i] * a[j];
		if(t >= 10) 
		{
    
			a.push_back(t / 10);
			a.push_back(t % 10);
		}
		
		else a.push_back(t);
		i++, j++;
	}
	
	rep(i, 0, n - 1)
	{
    
		cout << a[i];
		if(i != n - 1) cout << ' ';
	}
	return 0;
}

到这,LV1算是全部更新完了,如有问题,可以在评论提出,博主看到一定回答!!!
后续可能会更新LV2的,,,haha。

原网站

版权声明
本文为[%xiao Q]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_52068218/article/details/122427560