安徽科技學院2014-2015-1學期電腦14級12班《C語言程式設計I》期末考試,c語言期末試題

來源:互聯網
上載者:User

安徽科技學院2014-2015-1學期電腦14級12班《C語言程式設計I》期末考試,c語言期末試題

1274 Problem A

十字架

Time Limit:1000MS  Memory Limit:65536K
Total Submit:5 Accepted:4

Description

現在給你一個7*7的正方形,讓你來數一數這個正方形中有多少的十字架。一個十字形為一個十字架,多個個十字架可以相連。

例如:1 1 0 1 0 1 0
1 1 1 1 1 1 1
1 0 1 0 0 1 0
1 0 1 0 0 1 0
1 1 1 1 1 1 1
0 0 1 0 1 1 1
0 1 1 1 1 1 1

中有4個十字架。

Input

輸入第一行有一個數T表示有T組測試資料。
接下來輸入T個7行7列的一個正方形。
每行中的兩個元素用空格隔開。

Output

每組輸出資料有一個數代表有幾個十字架,每組資料佔一行。

Sample Input

21 1 0 1 0 1 01 1 1 1 1 1 11 0 1 0 0 1 01 0 1 0 0 1 01 1 1 1 1 1 10 0 1 0 1 1 10 1 1 1 1 1 10 1 0 1 0 1 11 1 1 1 1 1 10 1 1 1 0 1 11 0 1 1 0 1 11 1 0 0 0 0 11 1 1 1 1 1 10 1 0 0 1 0 1

Sample Output

45

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>using namespace std;int main() {    int a[8][8]= {0};    int n;    cin>>n;    while(n--) {        for(int i=0; i<7; i++)            for(int j=0; j<7; j++)                cin>>a[i][j];        int count=0;        for(int i=1; i<6; i++)            for(int j=1; j<6; j++)                if(a[i][j-1]==1&&a[i][j+1]==1&&a[i+1][j]==1&&a[i-1][j]==1&&a[i][j]==1)count++;        cout<<count<<endl;    }    return 0;}

1276 Problem B

找數

Time Limit:1000MS  Memory Limit:65536K
Total Submit:180 Accepted:78

Description

很簡單,下面有三個數n,m1,m2,就是讓設計一個程式找出能被m1或被m2整除的個數。

Input

輸入包含多組測試資料,每組資料佔一行。
0〈n〈2^31,0〈m1,m2〈=10。

Output

[1,n)中能被滿m1或者m2整除的個數
每組資料輸出佔一行。

Sample Input

12 2 3

Sample Output

7

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>using namespace std;int main() {    int a,b,c;    while(cin>>a>>b>>c) {        int d=0;        for(int i=1; i<a; i++)            if(i%b==0||i%c==0)                d++;        cout<<d<<endl;    }    return 0;}

1277 Problem C

奇異的碰撞

Time Limit:1000MS  Memory Limit:65536K
Total Submit:11 Accepted:4

Description

一天,一個生物學家發現了一種菌落碰撞的規律;他發現兩個權重M1和M2的菌落碰撞在一起會變成權重為2*sqrt(M1*M2)新菌落,現在培養皿中有一批菌落;現在菌落中發生碰撞,求碰撞之後剩下最後的一個菌落的(最小)權重;
輸入:

Input

第一行輸入一個整數N,表示菌落的數量;隨後有N個數表示菌落的權重;

Output

最後一個菌落的(最小)權重;結果保留三位小數;

Sample Input

3723050

Sample Output

120.000

Source

[Submit]   [Go Back]   [Status]   [Discuss]


#include <iostream>#include<algorithm>#include<cmath>#include<cstdio>double f(double n, double m) {return 2 * sqrt(n * m);}using namespace std;int main() {int n, a[1001];cin >> n;for (int i = 0; i < n; i++)cin >> a[i];sort(a, a + n);double s = f(a[n - 1], a[n - 2]);for (int i = n - 3; i >= 0; i--)s = f(s, a[i]);printf("%.3lf", s);return 0;}

1279 Problem D


疊硬幣的遊戲

Time Limit:2000MS  Memory Limit:65536K
Total Submit:17 Accepted:5

Description

小明把存錢罐裡的硬幣倒出來準備買東西,但是買東西之前小明想玩一個遊戲,就是想把硬幣疊成一樣的高度,你需要算出最少需要移動的硬幣數,假設初始的硬幣是一層一層的疊好的;
輸入

Input

多組測試資料,以EOF結束,第一行是一個n(1<=n<=50)表示有n堆硬幣;
第二行是n個正整數k(1<=k<=100)表示每堆硬幣的硬幣數量
如果n==0運行結束。

Output

對於每組輸入資料有兩行輸出,第一行是一個Case #x,表示x組測試資料,第二行輸出y.表示最小的移動磚塊的數量為y,若無解就輸出No solution

Sample Input

65 2 4 1 7 521 242 2 2 20

Sample Output

Case #15No solutionCase #20

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>#include<algorithm>using namespace std;int main() {    int n,cas=0;;    while( cin>>n) {            if(n==0)break;        int a[1001],sum=0;        for(int i=0; i<n; i++) {            cin>>a[i];            sum+=a[i];        }        if(sum%n!=0) {            cout<<"No solution"<<endl;            continue;        } else {            int tt=sum/n,count=0;            sort(a,a+n);            for(int i=0; i<n,a[i]<tt; i++)                count+=tt-a[i];            cas++;            cout<<"Case #"<<cas<<endl;            cout<<count<<endl;        }    }    return 0;}

1281 Problem E


奇怪的電話號碼

Time Limit:3000MS  Memory Limit:65536K
Total Submit:105 Accepted:58

Description

一天小明最近接到了一個棘手的任務,他們公司有一個電話簿.但是這是一個奇怪的電話簿,因為它不是用數字記錄電話號碼,而是用數字鍵上所對應的字母來記錄電話號碼(2-abc,3-def,4-ghi,5-jkl,6-mno,7-pqrs,8-tuv,9-wxyz),電話號碼只有11位。現在你的任務就是幫小明寫一個程式來把這些字母的電話號碼轉化成數位電話號碼。

Input

第一行輸入一個正整數T(0每組測試資料只有一行,輸入一串字元(字元長度為11);

Output

每組輸出佔一行,輸出數位電話號碼

Sample Input

2phqghumeaylnlfdxfircvs

Sample Output

7474486329565339347287

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>#include<string>using namespace std;int main() {    int n;    cin>>n;    while(n--) {        string s;        cin>>s;        for(int i=0; i<11; i++) {            if(s[i]=='a'||s[i]=='b'||s[i]=='c')cout<<"2";            if(s[i]=='d'||s[i]=='e'||s[i]=='f')cout<<"3";            if(s[i]=='g'||s[i]=='h'||s[i]=='i')cout<<"4";            if(s[i]=='j'||s[i]=='k'||s[i]=='l')cout<<"5";            if(s[i]=='m'||s[i]=='n'||s[i]=='o')cout<<"6";            if(s[i]=='p'||s[i]=='q'||s[i]=='r'||s[i]=='s')cout<<"7";            if(s[i]=='t'||s[i]=='u'||s[i]=='v')cout<<"8";            if(s[i]=='w'||s[i]=='x'||s[i]=='y'||s[i]=='z')cout<<"9";        }        cout<<endl;    }    return 0;}

1283 Problem F


資料的處理

Time Limit:4000MS  Memory Limit:65536K
Total Submit:13 Accepted:8

Description

小明先用電腦產生了N個1到1000之間的隨機整數(0〈N≤1000),對於其中重複的數字,只保留一個,把其餘相同的數去掉,不同的數對應著不同的學生的學號。然後再把這些數從小到大排序,按照排好的順序去找同學做調查。請你協助小明完成“去重”與“排序”的工作。

Input

輸入有3行,第1行為1個正整數T(0第3行有N個用空格隔開的正整數,為所產生的隨機數。

Output

輸出是2行,第1行為1個正整數M,表示不相同的隨機數的個數。第2行為M個用空格隔開的正整數,為從小到大排好序的不相同的隨機數。

Sample Input

11020 40 32 67 40 20 89 300 400 15

Sample Output

815 20 32 40 67 89 300 400

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>#include<algorithm>using namespace std;int main() {    int n;    cin>>n;    while(n--) {        int m,a[1001];        cin>>m;        for(int i=0; i<m; i++)            cin>>a[i];        sort(a,a+m);        int count=0;        for(int i=0; i<m; i++)            if(a[i]!=a[i+1])                count++;        cout<<count<<endl;        for(int i=0; i<m; i++)            if(a[i]!=a[i+1])                cout<<a[i]<<" ";        cout<<endl;    }    return 0;}

1284 Problem G


最大值和序號

Time Limit:1000MS  Memory Limit:65536K
Total Submit:142 Accepted:56

Description

輸入n個整數,求這n個數的最大值和序號!

Input

輸入n個整數
有多組資料
T a1 a2....at
...

Output

求這n個數的最大值和序號!
每組資料輸出兩行第一行為最大值,第二行為最大值所在的序號

Sample Input

31 2 341 2 3 3

Sample Output

3232 3

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>using namespace std;int main() {    int n;    while(cin>>n) {        int max=0,a[1001];        for(int i=0; i<n; i++) {            cin>>a[i];            if(a[i]>max)max=a[i];        }        cout<<max<<endl;        for(int i=0; i<n; i++)            if(a[i]==max)                cout<<i<<" ";        cout<<endl;    }    return 0;}

1285 Problem H


集合差

Time Limit:1000MS  Memory Limit:65536K
Total Submit:13 Accepted:10

Description

集合A-B被定義為由所有在A中但不在B中的元素組成的集合。例如A={1,2,3,4,5};B={2,4,6}則C=A-B={1,3,5}

Input

輸入集合A和集合B

Output

輸出集合C

Sample Input

5 1 2 3 4 53 2 4 6

Sample Output

3 1 3 5

Hint

數字已經有序,集合的輸出格式:集合長度 集合元素1.集合元素2.....

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>using namespace std;int main() {    int a[1001],b[1001],m,n;    cin>>m;    for(int i=0; i<m; i++)        cin>>a[i];    cin>>n;    for(int i=0; i<n; i++)        cin>>b[i];    int k=0,j=0,c[1001];    for(int i=0; i<m; i++) {        if(a[i]!=b[j]) {            c[k]=a[i];            k++;        } else  j++;    }    cout<<k;    for(int i=0; i<k; i++)        cout<<" "<<c[i];    cout<<endl;    return 0;}

1286 Problem I


大寫母音字母

Time Limit:1000MS  Memory Limit:65536K
Total Submit:122 Accepted:73

Description

輸入一個字串(不含空格)你的任務是將其中的母音字母都轉換成大寫字母並將其輸出!

Input

多組資料輸入
每行長度不超過100

Output

輸出轉換後的單詞

Sample Input

acmicpcAhstu

Sample Output

AcmIcpcAhstU

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>#include<string>using namespace std;int main() {    string a;    while(cin>>a) {        for(int i=0; i<a.size(); i++) {            if(a[i]=='a')a[i]='A';            if(a[i]=='o')a[i]='O';            if(a[i]=='e')a[i]='E';            if(a[i]=='i')a[i]='I';            if(a[i]=='u')a[i]='U';        }        cout<<a<<endl;    }    return 0;}

1282 Problem J


數的另一種表示方法

Time Limit:4000MS  Memory Limit:65536K
Total Submit:70 Accepted:45

Description

下面我們定義 f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;
給你一個x和一個數y;你需要求出y+f(x)的結果;

Input

第一行輸入一個數t(0

Output

y+f(x)的結果;

Sample Input

6R 1P 2G 3r 1p 2g 3

Sample Output

191810-17-14-4

Source

[Submit]   [Go Back]   [Status]   [Discuss]

#include<iostream>using namespace std;int main() {    int n;    cin>>n;    while(n--) {        char s;        int m;        cin>>s>>m;        if(s>='A'&&s<='Z')cout<<s-64+m<<endl;        if(s>='a'&&s<='z')cout<<-(s-96-m)<<endl;    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.