關於PAT乙級一些題目要點的重新整理(三)

2021-08-27 11:58:27 字數 3342 閱讀 4868

1050(題目及原解答

1.建立座標系,將幾個關鍵位置的座標寫出來,方便思考

2.注意不要產生資料的位置重疊,否則會有資料被覆蓋

3.m、n與level的確定:求出n的開方數,向下取整。從此數開始,向下判斷是否可被n整除,若可以則此數為n,得到n後便可求m。level為m除以2向上取整

#include#include#include#includeusing namespace std;

bool cmp(int a, int b)

int main()

sort(v.begin(), v.end(), cmp);

int temp = sqrt(n);

while(temp != 0)

temp--;

} int n = temp;

int m = n / n;

int level = m / 2 + m % 2;

vector> arr(m);

for(int i = 0; i < m; i++)

int index = 0;

for(int i = 0; i < level; i++)

for(int j = i; j < m - i - 1 && index < n; j++)

for(int j = n - i - 1; j > i && index < n; j--)

for(int j = m - i - 1; j > i && index < n; j--)

} for(int i = 0; i < m; i++)else

} }return 0;

}

1051(題目及原解答

1.注意a與b在》=-0.005, < 0時輸出0.00

#include#includeusing namespace std;

int main()else

if(b >= -0.005 && b <= 0)else if(b > 0)else

return 0;

}

1052(題目及原解答

1.無開頭結尾的輸入輸出採用字串整行輸入

2.注意所需符號為字串時,可以先設一空串,將字元逐個與之相加得到所需符號

#include#include#includeusing namespace std;

int main()

v[i].push_back(temp);

}} }

int n;

cin >> n;

for(int i = 0; i < n; i++)else

} return 0;

}

1054(題目及原解答

1.思路:向s1輸入字串,用sscanf從s1向d輸入浮點數(無需限制數字),然後用sprintf從d向s2輸入字串,若s1與s2相同則合法

2.s1、s2最好用字元陣列,且長度最好設在50以上,否則會re

#include#include#includeusing namespace std;

int main()

} if(isvalid == true && fabs(d) <= 1000)else

} if(cnt == 0)else if(cnt == 1)else

return 0;

}

1055(題目及原解答

1.完成輸入資料、排序等任務後,從最後一行開始,兩個迴圈從中間向兩邊輸出

2.將行數作為變數進行迴圈

#include#include#include#includeusing namespace std;

struct stu;

bool cmp(stu a, stu b)else if(a.name != b.name)

}int main()

sort(v.begin(), v.end(), cmp);

int row = k;

int index = 0;

int m;

while(row != 0)else

vectorline(m);

int i1 = index;

int i2 = index + 1;

for(int i = m / 2; i < line.size(); i++, i1 += 2)

for(int i = m / 2 - 1; i >= 0; i--, i2 += 2)

for(int i = 0; i < line.size(); i++)else

} index += m;

row--;

} return 0;

}

1060(題目及原解答

1.e的值不應當直接從數列中取,因為e可能為不存在於數列中的數

2.第n個數應大於n而不是大於等於n(v[i] > i + 1)

#include#include#includeusing namespace std;

bool cmp(int a, int b)

int main()

sort(v.begin(), v.end(), cmp);

int e = 0;

for(int i = 0; i < v.size(); i++)

e++;

} cout << e << endl;

return 0;

}

1068(題目及原解答

1.所符合要求的點並不是周圍八個均色差充分大,而是沒有不超過tol的點

#include#include#include#define maxn 1001

using namespace std;

long pic[maxn][maxn] = ;

int dire[8][2] = , , , , , , , };

int main()

} bool isunique = true;

bool i***ist = false;

int x, y;

long value;

for(int i = 0; i < n; i++)

}if(cnt == 0)else if(i***ist == true)

}

}} }

if (i***ist == false)

if (isunique == false)

if (i***ist == true && isunique == true)

return 0;

}

關於PAT乙級一些題目要點的重新整理(二)

1028 題目及原解答 1.注意若組數為0時的輸出 include include include includeusing namespace std struct person bool cmp person a,person b int main sort v.begin v.end cmp ...

一些有關PAT乙級考試的內容

1.判斷素數 bool isprime int n 2.解決執行超時問題 1 把cin換為scanf 把cout換為printf 2 在輸入之前加上std ios sync with stdio false 語句 方法 1 和方法 2 不能同時使用。3.大寫字母轉化為小寫字母 string func...

關於素數的一些題目

看了czyuan的總結,決定先找幾道素數的題目玩玩.首先,判定素數的方法除了暴力列舉到根號n外還有篩法,不要小看,他可以演變出一些題目 for i 2 i maxn i 短短幾行,可以在0.9s左右篩出一千萬內的素數,應該夠用了 這個題 是篩素數的好題,當然要先知道威爾遜定理.不知道的話搜一下吧.這...