Submission #880730

# Submission time Handle Problem Language Result Execution time Memory
880730 2023-11-30T00:27:40 Z tsumondai Kemija (COCI22_kemija) C++14
0 / 50
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 1e6 + 5;

const int oo = 1e9, mod = 1e9 + 7;

int n, m, k;
string s;
vector<int> arr;
int cnta[27], cntb[27];


void process() {
	memset(cnta, 0, sizeof(cnta));
	memset(cntb, 0, sizeof(cntb));
	int idx = 0;
	cin >> s;
	n = s.length();
	s = ' ' + s;
	foru(i, 1, n) {
		if (s[i] == '-') idx = i;
	}

	//cout << idx;
	string a = s.substr(1, idx - 1);
	string b = s.substr(idx + 2, n - idx);

	int mula = 1, mulb = 1;

	if (a[0] >= '1' && a[0] <= '9') mula = a[0] - '0';
	if (b[0] >= '1' && b[0] <= '9') mulb = b[0] - '0';

	foru(i, 1, a.length() - 1) {
		if (a[i] == '+' && a[i + 1] >= '0' && a[i + 1] <= '9') mula = a[i + 1] - '0', i++;
		else if (a[i+1] >= '0' && a[i+1] <= '9') cnta[a[i] - 'A'] = cnta[a[i] - 'A'] + (a[i+1] - '0') * mula, i++;
		else if (a[i] >= 'A' && a[i] <= 'Z') cnta[a[i] - 'A'] += mula;
	}

	foru(i, 1, b.length() - 1) {
		if (b[i] == '+' && b[i + 1] >= '0' && b[i + 1] <= '9') mulb = b[i + 1] - '0', i++;
		else if (b[i+1] >= '0' && b[i+1] <= '9') cntb[b[i] - 'A'] = cntb[b[i] - 'A'] + (b[i+1] - '0') * mulb, i++;
		else if (b[i] >= 'A' && b[i] <= 'Z') cntb[b[i] - 'A'] += mulb;
	}


	foru(i, 0, 25) {
		if (cnta[i] != cntb[i]) {
			cout << "NE\n";
			return;
		}
		//cout << (char) (i + 'A') << ':' << cnta[i] << ' ' << cntb[i] << '\n';
	}

	cout << "DA\n";

	return;
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);
	int t;
	cin >> t;
	while (t--) process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:

*/

Compilation message

Main.cpp: In function 'void process()':
Main.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
   46 |  foru(i, 1, a.length() - 1) {
      |       ~~~~~~~~~~~~~~~~~~~~              
Main.cpp:46:2: note: in expansion of macro 'foru'
   46 |  foru(i, 1, a.length() - 1) {
      |  ^~~~
Main.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define foru(i, l, r) for(int i = l; i <= r; i++)
......
   52 |  foru(i, 1, b.length() - 1) {
      |       ~~~~~~~~~~~~~~~~~~~~              
Main.cpp:52:2: note: in expansion of macro 'foru'
   52 |  foru(i, 1, b.length() - 1) {
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -