QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#331963#7698. ISBN Conversioncry#WA 1ms3596kbC++203.0kb2024-02-19 01:39:592024-02-19 01:39:59

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 01:39:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3596kb
  • [2024-02-19 01:39:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

map<char, string> mp;

void envy(){
	mp['A'] = "01";
	mp['B'] = "1000";
	mp['C'] = "1010";
	mp['D'] = "100";
	mp['E'] = "0";
	mp['F'] = "0010";
	mp['G'] = "110";
	mp['H'] = "0000";
	mp['I'] = "OO";
	mp['J'] = "0111";
	mp['K'] = "101";
	mp['L'] = "0100";
	mp['M'] = "11";
	mp['N'] = "10";
	mp['O'] = "111";
	mp['P'] = "0110";
	mp['Q'] = "1101";
	mp['R'] = "010";
	mp['S'] = "000";
	mp['T'] = "1";
	mp['U'] = "001";
	mp['V'] = "0001";
	mp['W'] = "011";
	mp['X'] = "1001";
	mp['Y'] = "1011";
	mp['Z'] = "1100";
	mp['0'] = "11111";
	mp['1'] = "01111";
	mp['2'] = "00111";
	mp['3'] = "00011";
	mp['4'] = "00001";
	mp['5'] = "00000";
	mp['6'] = "10000";
	mp['7'] = "11000";
	mp['8'] = "11100";
	mp['9'] = "11110";
}

#define ex {cout << "invalid" << endl; return;}

bool isdigit(char c){
	return c >= '0' && c <= '9';
}

void bruh(){
	string s; cin >> s;
	int n = s.size();
	if(s[0] == '-' || s.back() == '-') ex
	vector<int> hyp, dig;
	for(int i = 0; i < n; i++){
		if(isdigit(s[i])){
			dig.push_back(s[i] - '0');
		}
		else if(s[i] == '-'){
			hyp.push_back(i);
		}
		else if(s[i] == 'X'){
			if(i != n - 1) ex 
			dig.push_back(10);
		}
	}
	if(dig.size() != 10) ex 
	if(hyp.size() > 3) ex 
	if(hyp.size() == 3 && hyp.back() != n - 2) ex 
	for(int i = 0; i < (int)hyp.size() - 1; i++){
		if(hyp[i + 1] - hyp[i] == 1) ex
	}
	int correct_checksum = 0;
	for(int i = 0; i < dig.size(); i++){
		correct_checksum += (10 - i) * dig[i];
	}
	if(correct_checksum % 11 != 0) ex 
	vector<int> newdig = {9, 7, 8};
	for(int i: dig) newdig.push_back(i);
	int checksum = 0;
	for(int i = 0; i < (int)newdig.size() - 1; i++){
		if(i % 2 == 0){
			checksum += newdig[i];
		}
		else{
			checksum += 3 * newdig[i];
		}
		checksum %= 10;
	}
	cout << checksum << endl;
	int v = (10 - checksum) % 10;
	cout << "978-" << s.substr(0, (int)s.size() - 1) << v << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	// envy();
	int t; cin >> t;
	while(t--){
		bruh();
	}
}

	// string s; cin >> s;
	// int n = s.size();
	// for(int i = 0; i < n - 1; i++){
	// 	if(s[i] == 'O' && s[i + 1] == 'O'){
	// 		cout << "INVALID" << endl;
	// 		return 0;
	// 	}
	// }
	// if(s.back() != 'O'){
	// 	cout << "INVALID" << endl;
	// 	return 0;
	// }
	// for(ll start = 3; start < 1000; start += 2){
	// 	ll res = start;
	// 	bool ok = true;
	// 	for(int i = n - 2; i >= 0; i--){
	// 		if(s[i] == 'E'){
	// 			res *= 2;
	// 		}
	// 		else{
	// 			res--;
	// 			if(res % 3 != 0){
	// 				ok = false;
	// 				break;
	// 			}
	// 			res /= 3;
	// 		}
	// 		if(s[i] == 'E' && res % 2 == 1){
	// 			ok = false;
	// 			break;
	// 		}
	// 		if(s[i] == 'O' && res % 2 == 0){
	// 			ok = false;
	// 			break;
	// 		}
	// 		if(__builtin_popcountll(res) == 1){
	// 			ok = false;
	// 			break;
	// 		}
	// 	}
	// 	if(ok){
	// 		cout << res << "\n";
	// 	//	break;
	// 	}
	// }

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3596kb

input:

4
3-540-4258-02
039428013X
3-540-42580-2
0-14-028333-3

output:

invalid
6
978-0394280134
1
978-3-540-42580-9
invalid

result:

wrong answer 2nd lines differ - expected: '978-0394280134', found: '6'