[PYTHON] Re: Competitive programming life starting from zero Chapter 1 1 "Only C ++ can be used"

Introduction

This article is a feature-length part expression that I can not read without tears, I am an engineer aspiring with the programming Wakaba mark on my chest, OT returns to death (retry) and solves the problem of competitive programming that was asked at At.Coder repeatedly. It is an article of. You may be desperate and disappear on the way, but at least I want to do it until I get a job! !!

First a simple profile

Name: OT Programming history: 3 months (TECH :: EXPERT 63 term) Languages that can be used: Ruby (level to make a simple website with Rails), C # (level to make a simple Othello with Unity), Python ("Hello World" level) Favorite celebrity: Gacky

First enemy

Well, there is no context, but I will solve the problem immediately. Lol Since it is the first time, it is the easiest way to accumulate experience points with A --Rounding. Then, the first question to commemorate! !!

Problem statement X and A are integers between 0 and 9. Output 0 when X is less than A and 10 when X is more than A.

** Constraints ** 0≤X,A≤9 All inputs are integers

... it's insanely easy! ?? As for the language, I tried using Python for practice. It is completely licking. Without knowing that this is the entrance to the swamp ...

Python of despair, C ++ of hope

x = int
a = int

if x < a:
  print("0")
else:
  print("10")

"This is fine for the code for the time being." I muttered, and a few seconds after I submitted the code, thinking "Python is easy", I saw the error statement and noticed the stupidity of my thoughts.

"Can't compare int type variables? Orz"

When I put the real number in the variable as it is, it worked without error, so I changed the code to make it a format to compare after having the numerical value input with Input ()

x = input()
a = input()
y = int(x)
b = int(a)

if y < b:
  print("0")
else:
  print("10")

This is still the same error. After this, I tried many times and tried to write in Ruby and C #, but the same error did not lead to the correct answer, and my heart was dyed in despair ...

OT "What should I do ..."

??? "Do you want power?"

OT "Who is it !?"

C ++ "My name is C ++. It is one of the most used languages in competitive programming."

OT "(I think one of the highest languages is wrong in Japanese) ... C ++ !! You say that you can solve this problem if you master it !?"

C ++ "Of course, but I use it with my heart. My amount of description is not comparable to Python."

[--C ++ has become a companion--]

OT "C ++ ... is a difficult language, but if you write while studying on this site (http://cpp-lang.sevendays-study.com/index.html), you may be able to do something about it !!"

↓ Here is the code written using C ++ that became a companion in this way ↓

#include <bits/stdc++.h>
using namespace std;

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A){
    cout << "0";
  }
  else {
    cout << "10";
  } 
  return 0;
}

I submitted it and was able to get the AC (correct answer) safely! !! 8888888888888888888

ef389ac05dcd5a69ae36d84f26e2bdb0.png This is the history of returning to this death ... It was a climax from the beginning ()

Finally

C ++ is often written, and although it is written on various sites with a high degree of learning difficulty, it may be easy to use. And I felt that the large amount of description may be a merit of being able to execute the processing as I wanted.

Also, if anyone knows how to write this in Python, please let me know. M (_ _) m

Thank you for reading! !!

Recommended Posts

Re: Competitive programming life starting from zero Chapter 1 1 "Only C ++ can be used"
Re: Competitive Programming Life Starting from Zero Chapter 1.3 "Sedo Tea"
Re: Competitive Programming Life Starting from Zero Chapter 1.2 "Python of Tears"
[Tweepy] Re: Twitter Bot development life starting from zero # 1 [python]
Re: Competitive programming life starting from zero In order for beginners to get as high a performance as possible ~ ABC154 ~ 156 with impressions ~
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]
[For beginners] Re: Genetic algorithm starting from zero [Artificial intelligence]