c语言程序设计竞赛策划书,2018年江西理工大学C语言程序设计竞赛(初级组)一

C语言竞赛初级组第一、二场答案:

https://www.cnblogs.com/xingkongyihao/p/10046918.html

A: 逆序对

时间限制: 1 s      内存限制: 128 MB

题目描述

1.整数序列中两个相邻的数,如果后面的数小于前面的数,则称这两个数值构成了一个逆序对。例如,整数序列10,4,16,8,21,18,9中包含了4个逆序对。从键盘上输入n个由空格分隔的整数,编程输出其中包含的逆序对的数量。

输入

第一行输入一个数字n(1≤n≤1000)

第二行输入n个由空格分隔的整数

输出

输出一个数字,表示逆序对的答案

样例输入

7

10 4 16 8 21 18 9

样例输出

4

果然就是比较相邻么

usingSystem;

usingSystem.Collections; usingSystem.Collections.Generic; usingSystem.IO; usingSystem.Linq; usingSystem.Runtime.InteropServices; public classProgram { public static voidMain() { int cunt = 0; int n =ri(); List a = new List(Console.ReadLine().Split()).ConvertAll(i => int.Parse(i)); for (int i = 1; i < n; i++) { if (a[i] < a[i - 1]) { cunt++; } } Console.WriteLine(cunt); Console.ReadKey(); } public static int ri() { return int.Parse(Console.ReadLine()); } static int[] rla(char sep = ‘ ‘) { return Array.ConvertAll(Console.ReadLine().Split(sep), e =>int.Parse(e)); } }

B: sky的圈圈

时间限制: 1 s      内存限制: 128 MB

题目描述

最近小S不高兴了,所以她就想画圈圈,有大有小的。而现在她想让你也画圈圈了^_^。

大小为3的圈圈是

gCtr6jF0AAAAASUVORK5CYII=,大小为4的圈圈是

7NhmLh+7iWgyURSWD+YnOoVOoVMwBegUTCeuKXQKnYIpQKdgOnFNoVMwp7wDVUogghlhgREAAAAASUVORK5CYII=,大小为5的圈圈是

r49pp7+EAAAAASUVORK5CYII=,依次类推。

输入

输入一个数字n(3≤n≤100)

输出

输出你画的圈圈。

样例输入

3

样例输出

*#*

#*#

*#*

画图画图。。

usingSystem;

usingSystem.IO; usingSystem.Linq; public classProgram { public static voidMain() { var n =ri(); char[,] Map = new char[200,200]; Map[0, 0] = ‘*‘; Map[0, n - 1] = ‘*‘; Map[n - 1, 0] = ‘*‘; Map[n - 1, n - 1] = ‘*‘; for (int i = 1; i < n-1; i++) { Map[0, i] = ‘#‘; Map[n - 1, i] = ‘#‘; } for (int i = 1; i < n - 1; i++) { Map[i, 0] = ‘#‘; Map[i, n-1] = ‘#‘; } for (int i = 1; i < n - 1; i++) { for (int j = 1; j < n - 1; j++) { Map[i, j] = ‘*‘; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Console.Write(Map[i,j]); } Console.WriteLine(); } Console.ReadKey(); } public static int ri() { return int.Parse(Console.ReadLine()); } static int[] rla(char sep = ‘ ‘) { return Array.ConvertAll(Console.ReadLine().Split(sep), e =>int.Parse(e)); } }

C: 找零钱

时间限制: 1 s      内存限制: 128 MB

题目描述

小明现在有x元,现在想买一件y(y≤x)元的物品,商店里有五种货币,100元、20元、10元、5元、1元无限张,服务员会以最小的数量找零钱。问小明用x元买了一件y元的物品后找了多少张零钱。

输入

输入x和y两个整数(1≤y≤x≤10000)

输出

输出找零钱的最小的数量

样例输入

101 66

样例输出

3

提示

用101元买了一件66元的物品,需要找35元,一张20元、一张10元和一张5元。

贪心,取模取模取模

usingSystem;

usingSystem.Collections; usingSystem.Collections.Generic; usingSystem.IO; usingSystem.Linq; usingSystem.Runtime.InteropServices; public classProgram { public static voidMain() { intcunt; int result = 0; List a = new List(Console.ReadLine().Split()).ConvertAll(i => int.Parse(i)); cunt = a[0] - a[1]; result += cunt / 100; cunt %= 100; result += cunt / 20; cunt %= 20; result += cunt / 10; cunt %= 10; result += cunt/5; cunt %= 5; result += cunt / 1; Console.WriteLine(result); Console.ReadKey(); } public static int ri() { return int.Parse(Console.ReadLine()); } static int[] rla(char sep = ‘ ‘) { return Array.ConvertAll(Console.ReadLine().Split(sep), e =>int.Parse(e)); } }

D: 编程语言

时间限制: 1 s      内存限制: 128 MB

题目描述

现在的编程越来越多了,比如C、C++、Java、Python、C#、PHP等等。现在给定n种编程语言,每种语言还会给一个[1,n]之间的随机值,保证不重复。现在让你按随机值从小到大排序,然后输出对应的语言。

输入

第一行输入一个整数n(1≤n≤20)

接下来nn行,每行有一个字符串和一个随机值,字符串表示一种语言,长度不超过20.随机值范围为[1,n]

输出

输出nn行,按随机值从小到大输出对应的语言

样例输入

4

Java 3

C 1

Python 4

C++ 2

样例输出

C

C++

Java

Python

排序排序排序排序

usingSystem;

usingSystem.Collections; usingSystem.IO; usingSystem.Linq; usingSystem.Runtime.InteropServices; public classProgram { public static voidMain() { var n =ri(); ArrayList al = newArrayList(); for (int i = 0; i < n; i++) { Language La = newLanguage(); var x =Console.ReadLine().Split(); La.xx = x[0]; La.yy = int.Parse(x[1]); al.Add(La); } Languagex languagex = newLanguagex(); al.Sort(languagex); Language Laa = newLanguage(); for (int i = 0; i < n; i++) { Laa =(Language) al[i]; Console.WriteLine(Laa.xx); } Console.ReadKey(); } public classLanguage { public stringxx; public intyy; } public classLanguagex:IComparer { public int Compare(object x, objecty) { return((Language) x).yy.CompareTo(((Language) y).yy); } } public static int ri() { return int.Parse(Console.ReadLine()); } static int[] rla(char sep = ‘ ‘) { return Array.ConvertAll(Console.ReadLine().Split(sep), e =>int.Parse(e)); } }

E: 四边形面积

时间限制: 1 s      内存限制: 128 MB

题目描述

有一个四边形,现在需要求它的面积

输入

输入四行,每行两个数整数x, y (1≤x,y≤1000),四个点是按逆时针输入的。

输出

输出四边形的面积,保留3位小数点,

样例输入

0 0

10 0

1 1

0 11

样例输出

10.500

提示

C语言中保留3位小数用%.3lf   用法:printf("%.3lf",result)

四边形分凸凹四边形。

W976OfHIWKgAAAABJRU5ErkJggg==

提示都告诉你了

#include

using namespacestd;

structPoint { floatx, y; }; float LinearIntegration(const Point &p1, const Point &p2) { return 0.5 * (p2.x - p1.x) * (p2.y +p1.y); } float ComputePolygonArea(const Point points[], intlength) { if (points == NULL || length <= 0) return 0.0; float area = 0.0; for (int i = 0; i < length - 1; ++i) { area += LinearIntegration(points[i], points[i + 1]); } area += LinearIntegration(points[length - 1], points[0]); return area >= 0.0 ? area : -area; } intmain() { intn; Point a[4]; for(int i=0; i<4;i++) cin>>a[i].x>>a[i].y; float ans = ComputePolygonArea(a,4); printf("%.3f\n",ans); return 0; }

F: 进制转换

时间限制: 1 s      内存限制: 128 MB

题目描述

给定一个区间[l, r],从l至r之间的所有数依次转换成16进制然后连在一起,接着再转换成10进制,最后再对15取模。

输入

输入两个是l, r (1≤l≤r≤106)

输出

输出对15取模的结果。

样例输入

10 14

样例输出

0

提示

样例说明:

10、11、12、13、14的16进制分别是a、b、c、d、e。依次连在一起是abcde,转换成10进制是703710,对15取模为0。

一般的转化。(a*16^n+b*16^(n-1)..)%15,展开,a%16*16^n%15,16%15就可以不考虑了,于是变成a%15+b%15..。于是简化成a+b+c+d+e。注意取模

usingSystem;

usingSystem.Collections; usingSystem.Collections.Generic; usingSystem.IO; usingSystem.Linq; usingSystem.Reflection.Emit; usingSystem.Runtime.InteropServices; public classProgram { public static voidMain() { var str = ""; List a = new List(Console.ReadLine().Split()).ConvertAll(i => int.Parse(i)); var sum = 0; for (int i = a[0]; i <= a[1]; i++) { var pa = Convert.ToString(i, 16); //var pa = Convert.ToInt32(x, 16).ToString(); var len =pa.Length; for (int j = 0; j < len; j++) { if (pa[j] == ‘a‘) { sum += (10); sum %= 15; } else if (pa[j] == ‘b‘) { sum += (11); sum %= 15; } else if (pa[j] == ‘c‘) { sum += (12); sum %= 15; } else if (pa[j] == ‘d‘) { sum += (13); sum %= 15; } else if (pa[j] == ‘e‘) { sum += (14); sum %= 15; } else if (pa[j] == ‘f‘) { sum += (15); sum %= 15; } else{ sum += int.Parse(pa[j].ToString()); sum %= 15; } } } Console.WriteLine(sum%15); Console.ReadKey(); } public static int ri() { return int.Parse(Console.ReadLine()); } static int[] rla(char sep = ‘ ‘) { return Array.ConvertAll(Console.ReadLine().Split(sep), e =>int.Parse(e)); } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值