Problem p02711 (C++) — buggy submission, verdict: Time Limit Exceeded

// You can die anytime, but living takes true courage.
// Every journey begins with a single step. We just have to have patience.
// Life is not a game of luck. If you wanna win, work hard.
// It’s more important to master the cards you’re holding
// than to complain about the ones your opponent was dealt.
// If you just submit yourself to fate, then that’s the end of it.

/*

struct P {
int x, y;
bool operator<(const P &p) {
if (x != p.x) return x < p.x;
else return y < p.y;
}
};


bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}

*/

/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\\  =  /0
                    ___/`---'\\___
                  .' \\\\|     |// '.
                 / \\\\|||  :  |||// \\
                / _||||| -:- |||||- \\
               |   | \\\\\\  -  /// |   |
               | \\_|  ''\\---/''  |_/ |
               \\  .-\\__  '-'  ___/-. /
             ___'. .'  /--.--\\  `. .'___
          ."" '<  `.___\\_<|>_/___.' >' "".
         | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |
         \\  \\ `_.   \\_ __\\ /__ _/   .-` /  /
     =====`-.____`.___ \\_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Akshay Vashishtha

//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these
differences you’ll be able to get past them and grow even closer.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define lld long long int
#define vll vector<long long int>
#define vs vector<string>
#define vint vector<int>
#define vp vector<pair<int, int>>
// #define
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
// indexed_set;
#define forl(i, a, b) for (int i = a; i <= b; i++)
#define forln(i, a, b) for (int i = a; i < b; i++)
lld mod = 1e9 + 7;
#define ps push_back
#define mk make_pair
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(false), cin.tie(NULL)
#define sv()                                                                   \\
  int t;                                                                       \\
  scanf("%d", &t);                                                             \\
  while (t--)
using namespace std;

// I too will obtain everything that I desire. Not because someone asked me to
// do it, but because I know in my heart that I have something worth fighting
// for. Whatever you do, enjoy it to the fullest. That is the secret of life.

int main() {
  int n;
  bool f = false;
  cin >> n;
  while (n != 0) {
    int tmp = n % 10;
    if (tmp == 7)
      f = true;
    n /= 10;
  }
  if (f)
    cout << "Yes\\n";
  else
    cout << "No\\n";
  return 0;
}


Error: TLE

Fixed submission:

// You can die anytime, but living takes true courage.
// Every journey begins with a single step. We just have to have patience.
// Life is not a game of luck. If you wanna win, work hard.
// It’s more important to master the cards you’re holding
// than to complain about the ones your opponent was dealt.
// If you just submit yourself to fate, then that’s the end of it.

/*

struct P {
int x, y;
bool operator<(const P &p) {
if (x != p.x) return x < p.x;
else return y < p.y;
}
};


bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}

*/

/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\\  =  /0
                    ___/`---'\\___
                  .' \\\\|     |// '.
                 / \\\\|||  :  |||// \\
                / _||||| -:- |||||- \\
               |   | \\\\\\  -  /// |   |
               | \\_|  ''\\---/''  |_/ |
               \\  .-\\__  '-'  ___/-. /
             ___'. .'  /--.--\\  `. .'___
          ."" '<  `.___\\_<|>_/___.' >' "".
         | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |
         \\  \\ `_.   \\_ __\\ /__ _/   .-` /  /
     =====`-.____`.___ \\_____/___.-`___.-'=====
                       `=---='

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Akshay Vashishtha

//It’s just pathetic to give up on something before you even give it a shot.
//Knowing you’re different is only the beginning. If you accept these
differences you’ll be able to get past them and grow even closer.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define lld long long int
#define vll vector<long long int>
#define vs vector<string>
#define vint vector<int>
#define vp vector<pair<int, int>>
// #define
// tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
// indexed_set;
#define forl(i, a, b) for (int i = a; i <= b; i++)
#define forln(i, a, b) for (int i = a; i < b; i++)
lld mod = 1e9 + 7;
#define ps push_back
#define mk make_pair
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(false), cin.tie(NULL)
#define sv()                                                                   \\
  int t;                                                                       \\
  scanf("%d", &t);                                                             \\
  while (t--)
using namespace std;

// I too will obtain everything that I desire. Not because someone asked me to
// do it, but because I know in my heart that I have something worth fighting
// for. Whatever you do, enjoy it to the fullest. That is the secret of life.

int main() {
  int n;
  bool f = false;
  cin >> n;
  while (n != 0) {
    int tmp = n % 10;
    if (tmp == 7)
      f = true;
  }
  if (f)
    cout << "YES\\n";
  else
    cout << "NO\\n";
  return 0;
}