A - Six Characters Editorial by en_translator


As stated in the Constraint, the length of \(S\) is either \(1\), \(2\), or \(3\).

  • If the length of \(S\) is \(1\), print \(6\) copies of \(S\);
  • If the length of \(S\) is \(2\), print \(3\) copies of \(S\);
  • If the length of \(S\) is \(3\), print \(2\) copies of \(S\).

We can do different process depending on the length of a string with the feature of conditional branch (like if statement) which is a standard feature of programming languages.

The following is a sample code in C++.

#include <iostream>
using namespace std;

int main(void)
{
  string s;
  cin >> s;
  
  if(s.size() == 1) cout << s+s+s+s+s+s << endl;
  if(s.size() == 2) cout << s+s+s << endl;
  if(s.size() == 3) cout << s+s << endl;
  
  return 0;
} 

posted:
last update: