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:
plaintextSmXwpKz 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 :plaintextTEMPETE mXK - On the first line, the string
- Assistantpython
def predict_solar_storm(S1: str, S2: str) -> None: # Créer une liste pour stocker les caractères communs common_chars = [] # Utiliser un ensemble pour stocker les caractères de S2 pour un accès rapide chars_in_S2 = set(S2) # Parcourir S1 pour trouver les caractères communs for char in S1: if char in chars_in_S2: common_chars.append(char) # Vérifier si les caractères communs apparaissent dans le même ordre dans S2 index_S2 = 0 for char in common_chars: index_S2 = S2.find(char, index_S2) if index_S2 == -1: print("NORMAL") return index_S2 += 1 if common_chars: print("TEMPETE") print(''.join(common_chars)) else: print("NORMAL") if __name__ == "__start__": import sys input = sys.stdin.read data = input().split() predict_solar_storm(data[0], data[1])
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.