Contest - 2014-2015-2學期計算機14級12班《C語言程序設計II》期末考試
Start time: 2015-07-03 19:05:00.0 End time: 2015-07-03 21:35:00.0
Current System Time: 2015-07-06 01:12:32.52 Contest Status: Ended
Problem Id | Title |
1321 Problem A | 10000小時定律 |
1319 Problem B | 四方定理 |
1312 Problem C | A difficult problem |
1313 Problem D | DNF又爆滿啦 |
1314 Problem E | 奇幻數字 |
1315 Problem F | 差值最大 |
1316 Problem G | 字符串替換 |
1107 Problem H | 閏年 |
[Standings] [Status] [Statistics]
閏年 Time Limit:1000MS Memory Limit:65536K Description 輸入年份判斷是否是閏年,如果是則輸出“yes"否則輸出"no" Input 輸入年份判斷是否是閏年, Output 如果是則輸出“yes"否則輸出"no" Sample Input
1900
Sample Output
no
Source lrj程序入門 |
#include "iostream"//n久以前寫的,姑且一看
using namespace std;
int main()
{
int year;
cin>>year;
if((year%4==0&&year%100!=0)||year%400==0)
cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
}
1312、
A difficult problem Time Limit:1000MS Memory Limit:65536K Description Today, I want to take a few minutes to speak with you-directly and clearly-about Ebola: what we're doing about it, and what you need to know. Because meeting a public health challenge like this isn't
just a job for government. All of us-citizens, leaders, the media-have a responsibility and a role to play. This is a serious disease, but we can't give in to hysteria or fear-because that only makes it harder to get people the accurate information they need.
We have to be guided by the science. We have to remember the basic facts. Input You will be given two numbers in the input Output please read the problem . Sample Input
12 34567891011
-999 753951
Sample Output
-11
1000
Hint 這是一道難題。。。。。。。。目測亞洲區域賽難度。。。。。。 Source
|
[Submit] [Go Back] [Status] [Discuss]
這題我都不想再講了,同學們看到英文題就感覺很難,外表不代表內在哎,最後在hint裏都加上了oppsite的意思了,都沒人寫,表示我非常傷心,唉,,,題意很簡單第一個數取反然後加一,注意使用long long/**
* Project Name: C++
* File Name: A_difficult_problem.cpp
* Created on: 2015年6月23日 下午2:57:16
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
//freopen("A.in", "r", stdin);
//freopen("A.out", "w", stdout);
long long a, b;
while (cin >> a >> b) {
cout << -a + 1 << endl;
}
return 0;
}
1313、
DNF又爆滿啦 Time Limit:1000MS Memory Limit:65536K Description 《地下城與勇士》是一款韓國網絡遊戲公司NEOPLE開發的免費角色扮演2D遊戲,由三星電子發行,並於2005年8月在韓國正式發佈。中國則由騰訊遊戲代理髮行於2008年6月。 Input 多組測試數據 Output 每個輸出一行,依次輸出爆滿的頻道個數,擁擠的頻道個數和順暢的頻道個數 Sample Input
12345
20000
66666
Sample Output
12 0 55
20 0 47
66 1 0
Source
|
[Submit] [Go Back] [Status] [Discuss]
哈,說道這題,當時我地下城在掛機就胡亂想到的,簡單的一塌糊塗/**
* Project Name: C++
* File Name: DNF.cpp
* Created on: 2015年6月23日 下午11:58:40
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
// freopen("A.in", "r", stdin);
//freopen("A.out", "w", stdout);
int n;
while(cin>>n) {
int bao=0,yong=0,shun=0;
bao=n/1000;
if(n%1000>=500)
yong++;
shun=67-bao-yong;
cout<<bao<<" "<<yong<<" "<<shun<<endl;
}
return 0;
}
1314、
奇幻數字 Time Limit:1000MS Memory Limit:65536K Description 給定兩個整數m,n,統計1-n的整數中有多少個奇幻數字,只要滿足以下兩個條件的任意一個,我們就稱其爲奇幻數字. Input 第一個數是T,表示測試數據的組數。 後面有T行,包括兩個整數m和n,m∈[1,9]且m∈Z n∈[1,1000000] Output 輸出奇幻數字的個數。 Sample Input
2
3 20
2 100
Sample Output
7
55
Source
|
[Submit] [Go Back] [Status] [Discuss]
數字的模和除運算,沒什麼難度,可能不少人對分離一個數的各個位有疑惑,監考的時候發現好多人竟然就是寫七個式子求然後比較,我只想說,我不想難爲你,這要是很大的範圍那怎麼行呢,還是用循環吧。/**
* Project Name: C++
* File Name: 奇幻數字.cpp
* Created on: 2015年6月23日 下午3:32:48
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
bool test1(int i, int m) {
if (i % m == 0)
return true;
return false;
}
bool test2(int i, int m) {
int i1 = i;
while (i1) {
if (i1 % 10 == m)
return true;
i1 /= 10;
}
return false;
}
int main() {
//freopen("A.in", "r", stdin);
//freopen("A.out", "w", stdout);
int t, m, n;
cin >> t;
while (t--) {
int count = 0;
cin >> m >> n;
for (int i = 1; i <= n; i++)
if (test1(i, m) || test2(i, m))
count++;
cout << count << endl;
}
return 0;
}
1315、
差值最大 Time Limit:1000MS Memory Limit:65536K Description 在給定的一個m*n的矩陣中,計算各列或各行累加和中最大值與最小值的差 Input 多組測試數據 Output 輸出最大的差值,每組數據輸出一行 Sample Input
3 3
1 4 7
2 5 8
3 6 9
0 0
Sample Output
18
Source
|
[Submit] [Go Back] [Status] [Discuss]
二維數組的求和,知道行和列怎麼求和,雖然這題看上去不難,實際上很多算法就是在操縱i,j值,實現一些很巧妙地運算,需要大量訓練,細細體會。/**
* Project Name: C++
* File Name: 差值最大.cpp
* Created on: 2015年6月23日 下午8:15:39
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
//freopen("A.in", "r", stdin);
// freopen("A.out", "w", stdout);
int m, n;
while (cin >> m >> n) {
if (m == 0 && n == 0)
break;
int a[55][55] = { 0 }, max = -1, min = 10000000;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
for (int i = 0; i < m; i++) { //計算每行累加和的最大最小值
int sum = 0;
for (int j = 0; j < n; j++) {
sum += a[i][j];
}
if (sum > max)
max = sum;
if (sum < min)
min = sum;
}
for (int j = 0; j < n; j++) { //計算每列累加和的最大最小值
int summ = 0;
for (int i = 0; i < m; i++) {
summ += a[i][j];
}
if (summ > max)
max = summ;
if (summ < min)
min = summ;
}
cout << max - min << endl;
}
return 0;
}
1316、
字符串替換 Time Limit:1000MS Memory Limit:65536K Description 編寫一個程序實現將字符串中的所有"you"替換成"we",如果不包含"you",則原樣輸出。 Input 輸入包含多行數據 Output 對於輸入的每一行,輸出替換後的字符串 Sample Input
you are good man
you And Me
You with you
Sample Output
we are good man
we And Me
You with we
Source
|
[Submit] [Go Back] [Status] [Discuss]
考慮題目難度沒有給一些奇怪的字符,讓很多人給第三個位置隨便符一個值都能過,因爲測試數據就都是字母,不想搞難了,畢竟就是水題。/**
* Project Name: C++
* File Name: 字符串替換.cpp
* Created on: 2015年6月23日 下午10:41:22
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<string>
using namespace std;
int main() {
//freopen("A.in", "r", stdin);
// freopen("A.out", "w", stdout);
string s;
while (getline(cin, s)) {
string s2 = "we";
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'y' && s[i + 1] == 'o' && s[i + 2] == 'u') {
s.replace(i, 3, s2);
}
}
cout << s << endl;
}
return 0;
}
1319、
四方定理 Time Limit:1000MS Memory Limit:65536K Description 數論中著名的“四方定理”講的是:所有自然數至多隻要用四個數的平方和就可以表示。 Input 輸入包含多行數據 Output 由於可能會出現多種情況,依次輸出最小的a,b,c,d即可 Sample Input
110
211
520
Sample Output
0 1 3 10
0 3 9 11
0 0 6 22
Source
|
[Submit] [Go Back] [Status] [Discuss]
暴力可以過,沒啥難度,但是你要知道break只能提跳一個for循環啊,監考時給不下三個人改了這題代碼,很多人不知道/**
* Project Name: C++
* File Name: 四方定理.cpp
* Created on: 2015年6月23日 下午11:08:40
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
freopen("A.in", "r", stdin);
freopen("A.out", "w", stdout);
int n;
while (cin >> n) {
bool flag = true;
for (int i = 0; i * i <= n; i++) //窮舉
if (flag) {
for (int j = 0; j * j <= n; j++)
if (flag)
for (int k = 0; k * k <= n; k++)
if (flag)
for (int l = 0; l*l <= n; l++)
if (i * i + j * j + k * k + l * l == n) {
cout << i << " " << j << " " << k << " "
<< l << endl;
flag = false;
}
}
}
return 0;
}
1321、
10000小時定律 Time Limit:1000MS Memory Limit:65536K Description 作家格拉德威爾在《異類》一書中指出: Input 多組測試數據,輸入以EOF結束 Output 輸出她成爲大牛的日期,輸出格式見示例 Sample Input
2015/6/23 1
2015/9/1 8
Sample Output
2042/11/14
2019/2/2
Hint 其實對於成功者來說,不管練習的過程枯燥與否,有趣與否,他們都必將付出遠遠超出常人的代價。心甘情願花上一萬個小時來打通任督二脈的人,大都不是尋常之輩。 Source
|
[Submit] [Go Back] [Status] [Discuss]
這題還是我上JAVA課想出來的,加上之前看到的這個勵志小故事,結果就想出來這麼一道題,雖然就有兩個人提交,雖然那寫的也不對,但題目還是出了一點問題,我自己寫的代碼有點問題,導致測試數據不對,實際是有的對,有的又不對,這題廢了我很長時間的,最後考完試把測試數據和標程改過來的,還是挺抱歉的。/**
* Project Name: C++
* File Name: 10000Hours.cpp
* Created on: 2015年6月23日 上午10:04:18
* Author: jtahstu
* QQ: 1373758426 E-mail:[email protected]
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int N = 10000;
const int d[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int calc(int month, int day) { //計算這一年還有多少天
int days = 0;
for (int i = month + 1; i <= 12; i++)
days += d[i];
return days + (d[month] - day + 1);
}
int main() {
// freopen("A.in","r",stdin);
//freopen("A.out","w",stdout);
int Satrt_year, Start_month, Start_day, hour;
while (~scanf("%d/%d/%d %d", &Satrt_year, &Start_month, &Start_day, &hour)) {
int days;
int End_year = Satrt_year, End_month = Start_month, End_day;
if (N % hour)
days = N / hour + 1;
else
days = N / hour;
while (days >= 365) {
End_year++;
days -= 365;
}
if (calc(Start_month, Start_day) > days) { //如果就在這一年內
//cout<<calc(Start_month, Start_day) <<endl;
//cout<<days<<endl;
if (days >= d[Start_month] - Start_day + 1) { //如果不在起始的月份
End_day = 0;
End_month++;
days =days-( d[Start_month] - Start_day + 1);
for (int i = Start_month + 1; i <= 12; i++) {
if (days >= d[i]) {
End_month++;
days -= d[i];
}
}
End_day=days;//臥槽,這裏多次一舉的,媽蛋
// End_day = Start_day + days; //這裏相加可能會大於這個月的天數
// if (End_day > d[End_month]) {
// End_month++;
// End_day -= d[End_month - 1];
// }
} else { //如果恰好在起始的月份
End_day = Start_day + days;
}
} else { //如果到達下一年
End_month = 1;
End_day = 0;
days -= calc(Start_month, Start_day);
End_year++;
for (int i = 1; i <= 12; i++) {
if (days >= d[i]) {
End_month++;
days -= d[i];
}
}
End_day += days;
}
cout << End_year << "/" << End_month << "/" << End_day << endl;
}
return 0;
}
最後排名:
最後成績也可看到,基本都是5道、4道題,最少2題,都及格了,這和我們去年的期末考試難度降得不要太多,大家開開心心結束了爲期兩學期的c語言學習,編程也算入門了,後面的路還有很長,望大家不忘努力,努力什麼時候都不晚,珍惜時間,大學四年很快,很快。