473
技術社區[雲棲]
全國信息水平第六屆C語言設計競賽複賽A卷答案
/*
有一個數學等式:AB*CD=BA*DC,式中的一個字母代表一
位數字,試找出所有符合上述要求的乘積式並打印輸出。
*/
#include <stdio.h>
#include <conio.h>
int main()
{
int A, B, C, D;
for (A = 1; A <= 9; A++)
{
for (B = 1; B <= 9; B++)
{
for (C = 1; C <= 9; C++)
{
for (D = 1; D <= 9; D++)
{
if (A == D && B == C )
{
printf("%d%d*%d%d=%d%d*%d%d\n", A, B, C, D, B, A, D, C);
}
}
}
}
}
getch();
return 0;
}
/*
2. 編程解決如下問題(50分)。
請在整數n=742683613984中刪除8個數字,使得餘下的數字按原次序組成的新數最小。要求如下:
(1)整數n和刪除數字的個數“8”在源程序中完成賦值,程序直接輸出運行結果;
(2)程序結果輸出先後被刪除的數字(之間以逗號分隔)和刪除後所得的最小數。
(提示:整數n可以以字符數組的方式定義、賦值和處理)
*/
#include <stdio.h>
#include <conio.h>
#define LEN 12
int main()
{
int str[LEN] = {7, 4, 2, 6, 8, 3, 6, 1, 3, 9, 8, 4};
int i, min, index, cnt = 0;
int result[LEN] = {0};
while (cnt < 4)//依次找出倒數最小的4個數
{
min = str[0];
for (i = 0; i < LEN; i++)
{
if (min > str[i])
{
min = str[i];
index = i;
}
}
result[index] = min;
str[index] = 100;
cnt ++;
}
cnt = 0;
for (i = 0; i < LEN; i++)
{
if (str[i] != 100)
{
if (cnt != 0)
putchar(',');
printf("%d", str[i]);
cnt++;
}
}
putchar(10);
for (i = 0; i < LEN; i++)
if (result[i] != 0)
printf("%d", result[i]);
putchar(10);
getch();
return 0;
}
/*
3. 附加題:編程解決如下問題(50分)。
(1)已知平麵上三個點:(7,1)、(4,6)、(5,8),判斷這三點
組成的三角形是何種三角形(銳角,直角,鈍角)(10分);
(2)對(1)問中的三角形,給出它的外接圓半徑(20分);
(3)已知平麵上6個點的坐標為:(7,1)、(4,6)、(5,8)、(6,2)、
(3,9)、(2,7),試求覆蓋這6個點的覆蓋圓最小半徑(20分)。
(要求:點坐標數據在程序初始化中賦值完成,程序運行後直接輸出結果,
不進行數據輸入;點坐標數據和題目要求完全一致,否則導致的結果不正確
視為程序編寫錯誤。)
*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define LEN 12
typedef struct POINT
{
int x;
int y;
}Point;
int cmp(const void *lhs, const void *rhs)
{
int *px = (int *)lhs;
int *py = (int *)rhs;
return *px > *py;
}
int main()
{
int x, y, flag = 0;
double a, b, c;
//------第一問---------------------------------------------
int a2 = (7 - 4) * (7 - 4) + (1 - 6) * (1 - 6);
int b2 = (7 - 5) * (7 - 5) + (1 - 8) * (1 - 8);
int c2 = (4 - 5) * (4 - 5) + (6 - 8) * (6 - 8);
if (a2 + b2 == c2 || a2 + c2 == b2 || b2 + c2 == a2)
{
printf("組成的是直角三角形\n");
}
else if (a2 + b2 > c2 || a2 + c2 > b2 || b2 + c2 > a2)
{
printf("組成的是鈍角三角形\n");
}
else
printf("組成的是銳角三角形\n");
//------第二問---------------------------------------------
for (x = 4; x <= 7 && !flag; x++)
{
for (y = 1; y <= 8; y++)
{
a = (x - 7) * (x - 7) + (y - 1) * (y - 1);
b = (x - 4) * (x - 4) + (y - 6) * (y - 6);
c = (x - 5) * (x - 5) + (y - 8) * (y - 8);
if (a - b < 1e-9 && b - c < 1e-9 && a - c < 1e-9)
{
printf("外接圓的半徑為:%.2f\n", sqrt(a));
flag = 1;
break;
}
}
}
//------第三問---------------------------------------------
Point pt[6] = {{7, 1}, {4, 6}, {5, 8}, {2, 7}, {6, 2}, {3, 9}};
//按橫坐標從小到大排序
qsort(pt, 6, sizeof(pt[0]), cmp);
//不知道這樣做對不對!
printf("%.2f", sqrt((pt[5/2].x - pt[5].x) * (pt[5/2].x - pt[5].x)
+ (pt[5/2].y - pt[5].y) * (pt[5/2].y - pt[5].y)));
getch();
return 0;
}
最後更新:2017-04-02 15:15:21
上一篇:
windows下的批處理的學習
下一篇:
微博口水仗:方舟子VS 周鴻禕
myeclipse+tomcat中出現org.apache.juli.logging.LogFactory以及ECLIPSE裏org.apache.catalina.startup.Bootstrap
到了 50 歲你還願意做編程工作嗎?
醫療大健康行業案例(老人健康實時監測和預警) - 阿裏雲RDS PostgreSQL最佳實踐
《Hadoop與大數據挖掘》一2.5.3 Hadoop K-Means算法實現思路
得到XmlHttpRequest對象封裝的函數,支持ie和firefox
通過Axon和Disruptor處理1M tps
大話數據結構之二:算法
JavaScript:Select標簽
01、什麼是ajax?
計算機硬盤大小轉換(B,KB,MB,GB,TB,PB之間的大小轉換)