pta 7 32 螺旋方陣 20分

2021-10-02 06:38:54 字數 949 閱讀 3239

所謂「螺旋方陣」,是指對任意給定的n,將1到n×n的數字從左上角第1個格仔開始,按順時針螺旋方向順序填入n×n的方陣裡。本題要求構造這樣的螺旋方陣。

輸入在一行中給出乙個正整數n(<10)。

輸出n×n的螺旋方陣。每行n個數字,每個數字佔3位。

5
1  2  3  4  5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

#include #include #include #include #include #include #include #include #include #include using namespace std;

#define ios \

ios::sync_with_stdio(false); \

cin.tie(0); \

cout.tie(0)

#define ll long long

#define met(a,b) memset(a,b,sizeof(a))

const int n = 1010;

int n,cnt,pd=1,one=1;

int arr[n][n];

int main()

for(int j=i+1;j<=n-one+1;j++)

for(int j=n-i;j>=one;j--)

for(int j=n-i;j>=one+1;j--)

one++;

}for(int i=1;i<=n;i++)

printf("\n");

}ios;

return 0;

}

PTA 7 32 說反話 加強版 20分

輸入格式 測試輸入包含乙個測試用例,在一行內給出總長度不超過500 000的字串。字串由若干單詞和若干空格組成,其中單詞是由英文本母 大小寫有區分 組成的字串,單詞之間用若干個空格分開。輸出格式 每個測試用例的輸出佔一行,輸出倒序後的句子,並且保證單詞間只有1個空格。輸入樣例 hello world...

PTA 7 32 計算天數

本題要求編寫程式計算某年某月某日是該年中的第幾天。輸入格式 輸入在一行中按照格式 yyyy mm dd 即 年 月 日 給出日期。注意 閏年的判別條件是該年年份能被4整除但不能被100整除 或者能被400整除。閏年的2月有29天。輸出格式 在一行輸出日期是該年中的第幾天。輸入樣例1 2009 03 ...

PTA 螺旋方陣

所謂 螺旋方陣 是指對任意給定的nnn,將1到n nn times nn n的數字從左上角第1個格仔開始,按順時針螺旋方向順序填入n nn times nn n的方陣裡。本題要求構造這樣的螺旋方陣。輸入格式 輸入在一行中給出乙個正整數nnn 10 10 10 輸出格式 輸出n nn times nn...