Submission #758115

# Submission time Handle Problem Language Result Execution time Memory
758115 2023-06-14T07:42:05 Z KN200711 Mobitel (COCI14_mobitel) C++14
50 / 50
1 ms 316 KB
# include <bits/stdc++.h>
# define ll long long
using namespace std;

int pos[10];

int val(char a) {
	int x = a - 'a';
	x /= 3;
	x += 2;
	if(a == 'p' || a == 'q' || a == 'r' || a == 's') return 7;
	if(a == 't' || a == 'u' || a == 'v') return 8;
	if(a == 'w' || a == 'x' || a == 'y' || a == 'z') return 9;
	return x;	
}

int ch(char a) {
	int x = a - 'a';
//	cout<<x<<endl;
	x %= 3;
	x++;
	if(a == 'p' || a == 't' || a == 'w') return 1;
	if(a == 'q' || a == 'u' || a == 'x') return 2;
	if(a == 'r' || a == 'v' || a == 'y') return 3;
	if(a == 's' || a == 'z') return 4;
	return x;	
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	for(int i=1;i<=9;i++) {
		int a;
		cin>>a;
		pos[a] = i;
	}
	
	string S;
	cin>>S;
	
	for(int i=0;i<S.length();i++) {
		if(i > 0 && val(S[i - 1]) == val(S[i])) {
			cout<<"#";
		}
		for(int d=0;d<ch(S[i]);d++) cout<<pos[val(S[i])];
	}
}

Compilation message

mobitel.cpp: In function 'int main()':
mobitel.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i=0;i<S.length();i++) {
      |              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 316 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct