求调
  • 板块灌水区
  • 楼主封禁用户
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/11/12 10:14
  • 上次更新2023/11/12 12:00:16
查看原帖
求调
1011137
封禁用户楼主2023/11/12 10:14
#include <bits/stdc++.h>
using namespace std;

int n;
int b[101][201], len[101], cnt, tmp[101], tmpsize;
int c[201], lc;

struct Info {
	string s;
	int v;
	int id;
} a[101];

bool operator < (Info x, Info y) {
	if (x.s != y.s)
		return x.s < y.s;
	else
		return x.id < y.id;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		cin >> a[i].s;
		scanf("%d", &a[i].v);
		a[i].id = i;
	}
	sort(a + 1, a + n + 1);
	for (int i = 2; i <= n; i++) {
		if (a[i].s != a[i - 1].s) {
			int x = a[i].v;
			++cnt;
			while (x) {
				b[cnt][++len[cnt]] = x % 10;
				x /= 10;
			}
			reverse(b[cnt] + 1, b[cnt] + len[cnt] + 1);
		} else {
			int x = a[i].v;
			memset(tmp, 0, sizeof(tmp));
			tmpsize = 0;
			while (x) {
				tmp[++tmpsize] = x % 10;
				x /= 10;
			}
			reverse(tmp + 1, tmp + tmpsize + 1);
			memset(c, 0, sizeof(c));
			lc = tmpsize + len[cnt];
			for (int j = 1; j <= tmpsize; j++)
				for (int k = 1; k <= len[cnt]; k++)
					c[j + k - 1] += tmp[j] * b[cnt][k];
			for (int j = 1; j <= lc; j++) {
				c[j + 1] += c[j] / 10;
				c[j] %= 10;
			}
			while (c[lc] == 0 && lc > 1)
				lc--;
			for (int j = 1; j <= lc; j++)
				b[cnt][j] = c[j];
			len[cnt] = lc;
		}
	}
	for (int i = 2; i <= cnt; i++) {
		if (len[i] >= len[i - 1])
			lc = len[i];
		else
			lc = len[i - 1];
		memset(c, 0, sizeof(c));
		for (int j = 1; j <= lc; j++) {
			c[j] += b[i][j] + b[i - 1][j];
			c[j + 1] /= 10;
			c[j] %= 10;
		}
		if (c[lc + 1] > 0)
			lc++;
		for (int j = 1; j <= lc; j++)
			b[i][j] = c[j];
		len[i] = lc;
	}
	for (int i = len[cnt]; i >= 1; i--)
		printf("%d", b[cnt][i]);
}

题目:

在一个古老的海岛,传说中有一位名叫“黑胡子”的海盗埋藏了他的巨大财宝。这位海盗留下了一张神秘的地图,地图上有许多奇怪的符号和数字。据说,只有解开这些符号和数字背后的秘密,才能找到这笔宝藏。

蜗蜗作为一个冒险家,决定挑战这个传说,解开这张地图的秘密,找到那笔宝藏!蜗蜗手中有 n 组线索。每组线索包括一个神秘的符号字符串 si 和一个数字 ai。为了找到宝藏,蜗蜗需要找到所有相同的符号字符串,并将它们对应的数字相乘,最后将所有的乘积结果相加(只出现一次也算作相同,即这个线索对应的数字也需要加入最后的答案)。最后的结果就是指向宝藏位置的密码,现在蜗蜗需要你的帮助。

输入格式 第一个行一个整数 n。

接下来 n 行,每行一个字符串 si 和一个数字 ai(用一个空格分开)。

输出格式 一行一个数字表示指向宝藏位置的密码。

样例输入 3 ad 2 ad 4 bcf 3 样例输出 11 样例解释 关于线索 ad 的数字是 2 和 4,关于线索 bcf 的数字是 3,最后的密码是 2×4+3=11。

数据范围 保证 1≤n≤100,1≤|si|≤10,1≤ai≤109。

2023/11/12 10:14
加载中...