码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-12-01 15:29:46      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:cms   abi   \n   mpp   msn   用法   hdr   mds   rand   

 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 (1n1000)

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

输出

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

样例输入

7
10 4 16 8 21 18 9

样例输出

4

果然就是比较相邻么
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

public class Program
{
    public static void Main()
    {
        int cunt = 0;
        int n = ri();
        List<int> a = new List<string>(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的圈圈是技术分享图片,大小为4的圈圈是技术分享图片,大小为5的圈圈是技术分享图片,依次类推。

输入

输入一个数字n (3n100)

输出

输出你画的圈圈。

样例输入

3

样例输出

*#*
#*#
*#*

画图画图。。
using System;
using System.IO;
using System.Linq;

public class Program
{
    public static void Main()
    {
        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 (yx)元的物品,商店里有五种货币,100元、20元、10元、5元、1元无限张,服务员会以最小的数量找零钱。问小明用x元买了一件y元的物品后找了多少张零钱。

输入

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

输出

输出找零钱的最小的数量

样例输入

101 66

样例输出

3

提示

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

贪心,取模取模取模

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

public class Program
{
    public static void Main()
    {
        int cunt;
        int result = 0;
        List<int> a = new List<string>(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 (1n20)

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

输出

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

样例输入

4
Java 3
C 1
Python 4
C++ 2

样例输出

C
C++
Java
Python

排序排序排序排序
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

public class Program
{
    public static void Main()
    {
        var n = ri();
        
        ArrayList al = new ArrayList();
        for (int i = 0; i < n; i++)
        {
            Language La = new Language();
            var x = Console.ReadLine().Split();
            La.xx = x[0];
            La.yy = int.Parse(x[1]);
            al.Add(La);
        }
        Languagex languagex = new Languagex();
        al.Sort(languagex);
        Language Laa = new Language();
        for (int i = 0; i < n; i++)
        {
            Laa = (Language) al[i];
            Console.WriteLine(Laa.xx);
        }

        Console.ReadKey();
    }

    public class Language
    {
        public string xx;
        public int yy;
    }
    public class Languagex:IComparer
    {
        public int Compare(object x, object y)
        {
            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, (1x,y1000),四个点是按逆时针输入的。

输出

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

样例输入

0 0
10 0
1 1
0 11

样例输出

10.500

提示

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

四边形分凸凹四边形。

技术分享图片

提示都告诉你了

#include<bits/stdc++.h>

using namespace std;
struct Point
{  
    float x, 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[], int length)
{  
    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;  
}  
int main()
{
    int n;
    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],从lr之间的所有数依次转换成16进制然后连在一起,接着再转换成10进制,最后再对15取模。

输入

输入两个是l(1lr106)

输出

输出对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。注意取模

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Runtime.InteropServices;

public class Program
{
    public static void Main()
    {
        var str = "";
        List<int> a = new List<string>(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)); }
}

 

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

标签:cms   abi   \n   mpp   msn   用法   hdr   mds   rand   

原文地址:https://www.cnblogs.com/yinghualuowu/p/10049038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!