CSP 201909-3损坏的RAID5

本来想把代码贴在回复里,字数有限贴不了,这里贴上完整代码。

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <map>
#include <string.h>

using namespace std;

map<int, char> mm;
const char* en = "0123456789ABCDEF";
void cacheMap();

int main() {
	ios::sync_with_stdio(false);
	int n, s, l, m, order, tempint, col, fd, sd, so, ps, maxBlock;
	string tempstr;
	cin >> n >> s >> l;
	string data[n];
	int a[n] = {0};
	for (int i = 0; i < l; i++) {
		cin >> tempint >> tempstr;
		a[tempint] = 1;
		data[tempint] = tempstr;
	}
	maxBlock = data[tempint].size() / 8 * (n - 1);
	cacheMap();
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> order;
		so = order / s; // 
		if (order >= maxBlock || (a[fd] == 0 && n - l >= 2)) { 
			cout << "-" << endl;
			continue; 
		}
		int stripes = so / (n - 1);
		fd = so % n;
		sd = stripes * s + (order % s);
		char result[9] = "00000000"; 
		if (a[fd] == 0) {
			for (int i = 0; i < n; i++) {
				if (i != fd) {
					for (int j=0;j<8;j++) {
						result[j] = mm[result[j]*128+(data[i][sd*8+j])];
					}
				}
			}
			cout << result;
		} else {
			for (int i=0;i<8;i++) {
				int start = sd * 8;
				cout << data[fd][start+i];	
			}
		}
		cout << endl;
	}
}

void cacheMap() {
	for (int i=0;i<16;i++) {
		for (int j =0;j<16;j++) {
			mm[en[i]*128+en[j]] = mm[en[j]*128+en[i]] = en[i^j];
		}
	} 
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值