Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
1215 - Mesaj
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Încărcare soluție == === Lipește codul aici === <syntaxhighlight lang="python" line="1"> import string in_file = open("mesaj.in", "r") out_file = open("mesaj.out", "w") maj_counts = [0] * 256 min_counts = [0] * 256 max_cost = [0] * 256 max_cost_counts = [0] * 256 P = int(in_file.readline()) N = int(in_file.readline()) num_secvente = 0 num_secvente_cu_cuvinte = 0 ch = '#' count_ch = 1 maj_ch = '#' min_ch = '#' for i in range(N): peek_ch = in_file.read(1) if i == N - 1: peek_ch = '#' if ch == peek_ch: count_ch += 1 else: if count_ch == 1: if P == 1 or P == 2 or P == 3: if ch.isupper() and maj_ch == '#': maj_ch = ch if ch.islower(): min_ch = ch if P == 3: if ch.isupper(): maj_counts[ord(ch)] += 1 if ch.islower(): min_counts[ord(ch)] += 1 elif count_ch == 2: if P == 1: num_secvente += 1 if maj_ch != '#' and min_ch != '#': num_secvente_cu_cuvinte += 1 maj_ch = min_ch = '#' elif P == 2: if maj_ch != '#' and min_ch != '#': out_file.write(maj_ch + min_ch + '\n') maj_ch = min_ch = '#' elif P == 3: if ch.isupper(): maj_counts[ord(ch)] += 2 if ch.islower(): min_counts[ord(ch)] += 2 if maj_ch != '#' and min_ch != '#': cost = maj_counts[ord(maj_ch)] + min_counts[ord(min_ch)] if cost > max_cost[ord(maj_ch)]: max_cost[ord(maj_ch)] = cost max_cost_counts[ord(maj_ch)] = 1 elif cost == max_cost[ord(maj_ch)]: max_cost_counts[ord(maj_ch)] += 1 maj_ch = min_ch = '#' maj_counts = [0] * 256 min_counts = [0] * 256 else: if P == 1: num_secvente += 1 maj_ch = min_ch = '#' elif P == 2: maj_ch = min_ch = '#' elif P == 3: maj_ch = min_ch = '#' maj_counts = [0] * 256 min_counts = [0] * 256 count_ch = 1 ch = peek_ch if P == 1: out_file.write(str(num_secvente - num_secvente_cu_cuvinte) + '\n') elif P == 3: for ch in string.ascii_uppercase: if max_cost[ord(ch)]: out_file.write(ch + ' ' + str(max_cost_counts[ord(ch)]) + '\n') in_file.close() out_file.close() </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width