AtCoder Beginner Contest 335 (Sponsored by Mynavi) (1)

problem 2013

You are given a string S consisting of lowercase English letters and digits.S is guaranteed to end with 2023.Change the last character of S to 4 and print the modified string.

solution
使的最后一个2023变为2024.

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
   string str;
   cin>>str;
   int p;
   int flag=0;
   for(int i=str.size()-1;i>=0;)
   {
       if(flag==1) break;
       if(str[i]=='3'&&str[i-1]=='2'&&str[i-2]=='0'&&str[i-3]=='2')
       {
           flag=1;
            p=i-4;
          
       }
   }
   //cout<<p<<endl;
   for(int i=0;i<=p;i++) cout<<str[i];
   cout<<"2024"<<endl;
    return 0;
}

problem Tetrahedral Number

You are given an integer N.Print all triples of non-negative integers (x,y,z) such that
x+y+z≤N in ascending lexicographical order.
solution
输出三个数,并且三个数的和小于等于n。按最小子序输出。

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
   int n;
   cin>>n;
   for(int i=0;i<=n;i++)
   {
       for(int j=0;j<=n;j++)
       {
           for(int k=0;k<=n;k++)
           if(i+j+k<=n)
           cout << i<<' '<<j<<' '<<k<<endl;
       }
   }
    return 0;
}

problem Loong Tracking
Takahashi has created a game where the player controls a dragon on a coordinate plane.

The dragon consists of N parts numbered 1 to N, with part 1 being called the head.

Initially, part i is located at the coordinates
(i,0). Process Q queries as follows.

solution
即记录字母的运动路径,将第一个字母不断地加入队列中即可。

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 417
#endif
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using f64 = double_t;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n, q;
  cin >> n >> q;
  deque<pair<int, int>> dp;
  for (int i = 0; i < n; i += 1) { dp.emplace_back(i + 1, 0); }
  for (int i = 0, op, p; i < q; i += 1) {
    cin >> op;
    if (op == 1) {
      char c;
      cin >> c;
      auto [x, y] = dp.front();
      if (c == 'R') { x += 1; }
      if (c == 'L') { x -= 1; }
      if (c == 'U') { y += 1; }
      if (c == 'D') { y -= 1; }
      dp.emplace_front(x, y);
      dp.pop_back();
    } else {
      cin >> p;
      auto [x, y] = dp
; cout << x << " " << y << " "; } } }

Problem Loong and Takahashi

solution
简单地来说,就是输出n*n的螺旋形状,并且使最后一项为T。

#include<iostream>
using namespace std;
int a[100][100];
int main(){
int n,i,j,k=1,l;
cin>>n;
l=n;
int temp=1;
while(temp<=n*n)
{
    for(i=k;i<=l;i++)a[k][i]=temp++;//第一行不变列增加                1 2 3 4
    for(i=k+1;i<=l;i++)a[i][l]=temp++;//第n列不变,从第二行开始增加    12 13 14  5
    for(i=l-1;i>=k;i--)a[l][i]=temp++;//第n行不变,从第n-1列减少      11 16 15  6               
    for(i=l-1;i>k;i--)a[i][k]=temp++; //第1列不变,行减少             10 9 8 7                            
    k++;
    l--;
}
int p=(n-1)/2 +1;
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        if(i==p&&j==p)
        cout<<"T"<<" ";
        else 
        cout<<a[i][j]<<" ";
    }
    cout<<endl;
}
   return 0;
}