affiche juste le code, pas d'explications !
- User
System: affiche juste le code, pas d'explications ! User: Tu es un développeur python3 expérimenté, et tu dois concevoir un programme en python (avec des commentaires en français, sans utiliser de librairies externes, sans
if __name__=="__main__":, avec type hints, et en privilégiant les algorythmes a complexité constante (O(1)) et/ou complexité linéaire (O(n))). Le programme va recevoir les données en entrée sur la stdin, et doit répondre sur la stdout. Fabrique moi un programme python qui résout le problème (énoncé en markdown) suivant :Solar Storm Prediction
You are quickly given your first assignment in the Brigade, protecting the city's systems from violent particle storms related to solar flares.
Thanks to the telescope in your backyard, you have been able to observe the sun for many days and have deduced a very interesting pattern: sunspots appear and disappear in an erratic way, but when a flare approaches you notice that some spots always appear in the same order!
In order to better predict the solar storms that threaten your infrastructure, you want to write an algorithm that takes as input two successive observations, and finds the sunspots that are common to both. If these spots appear in the same order, you risk an imminent flare!
Data
Input
Line 1: a string S1 of letters representing the first solar activity pattern. Line 2: a string S1 of letters representing the second solar activity pattern.
Output
If the common letters between S1 and S2 appear in the same order between the two patterns, display two lines:
- On the first line, the string
TEMPETE - On the next line, the common characters between S1 and S2, in their order of appearance in both strings
If there are no common letters or they are not in the same order, print
NORMALon one line.Constraints
- Characters are unique within each string.
- Characters are upper or lower case letters.
Example
For the entry:
SmXwpKz meXZKiThree letters appear in common:
m,XandK. Since they appear in the ordermXKin S1 and S2, a storm is imminent and you need to print :TEMPETE mXKNote that sunspots
zandZare considered different.Example 2
For the input :
LMepmWsAO kMrTpOmzIfHere, the common elements are
M,p,mandO. However, they appear in S1 in the orderMpmOand in S2 in another orderMpOm. Thus, there is no abnormal activity and you should display :NORMALAssistant:
- On the first line, the string
- Assistant
def detect_flare(s1: str, s2: str) -> None: # Ensemble des caractères dans s2 pour un accès en temps constant s2_set = set(s2) # Liste des caractères communs dans l'ordre de s1 common_in_s1 = [ch for ch in s1 if ch in s2_set] # Initialisation des variables j = 0 common_in_s2 = [] # Parcours de s2 pour trouver l'ordre des communs basé sur common_in_s1 for ch in s2: if j < len(common_in_s1) and ch == common_in_s1[j]: common_in_s2.append(ch) j += 1 # Vérification si les ordres des communs sont les mêmes if common_in_s1 == common_in_s2: print("TEMPETE") print("".join(common_in_s1)) else: print("NORMAL") # Lecture des entrées stdin et exécution de la fonction import sys input_data = sys.stdin.read().strip().split() s1 = input_data[0] s2 = input_data[1] detect_flare(s1, s2)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.