# 如何使用給定的四個鍵打印A的最大數量

## 問題陳述

1. Key1 –在屏幕上打印“ A”
2. Key2 –選擇整個屏幕。
3. Key3 –複製所選內容。
4. Key4 –打印複製的內容。

## 例

`Number of keys that can be pressed = 2`
`Number of A's that can be printed = 2`

`Number of keys that can be pressed = 6`
`Number of A's that can be printed = 6`

## 推薦碼

### C ++代碼查找可以打印的最大As數

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

int maximumNumberOfAsPrinted(int numberOfKeyPresses)
{
if(numberOfKeyPresses <= 6)
return numberOfKeyPresses;

int maxNumberOfAs = 0;
for(int i = numberOfKeyPresses-3; i>=1;i--) {
// here we consider that after ith keystroke we are performing only selection, copy once and then paste
// thus starting from numberOfKeyPresses-3
int numberOfAs = (numberOfKeyPresses-i-1)*maximumNumberOfAsPrinted(i);
if (numberOfAs > maxNumberOfAs)
maxNumberOfAs = numberOfAs;
}
return maxNumberOfAs;
}

int main()
{
int numberOfKeyPresses;cin>>numberOfKeyPresses;
int numberOfAsPrinted = maximumNumberOfAsPrinted(numberOfKeyPresses);
cout<<numberOfAsPrinted;
}
```
`18`
`192`

### Java代碼查找可以打印的最大As數

```import java.util.*;

class Main{
static int maximumNumberOfAsPrinted(int numberOfKeyPresses)
{
if(numberOfKeyPresses <= 6)
return numberOfKeyPresses;

int maxNumberOfAs = 0;
for(int i = numberOfKeyPresses-3; i>=1;i--) {
// here we consider that after ith keystroke we are performing only selection, copy once and then paste
// thus starting from numberOfKeyPresses-3
int numberOfAs = (numberOfKeyPresses-i-1)*maximumNumberOfAsPrinted(i);
if (numberOfAs > maxNumberOfAs)
maxNumberOfAs = numberOfAs;
}
return maxNumberOfAs;
}

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int numberOfKeyPresses = sc.nextInt();
int numberOfAsPrinted = maximumNumberOfAsPrinted(numberOfKeyPresses);
System.out.println(numberOfAsPrinted);
}
}```
`18`
`192`