参考答案(不全对)c#pta

开头添加using System;可以去掉代码里的system

方法一

using System.Collections;
internal class Program{
    static void Main(string[] args){
        int n = System.Convert.ToInt32(System.Console.ReadLine());
        string na = System.Console.ReadLine();
        string[]s1=na.Split(new char[]{' '});
        int[] str =new int[n];
        for(int i =0;i<n;i++){
            str[i]=int.Parse(s1[i]);
        }
        ArrayList list=new ArrayList(str);
        int nm = System.Convert.ToInt32(System.Console.ReadLine());
        for(int i=0;i<nm;i++){
            int num=System.Convert.ToInt32(System.Console.ReadLine());
            list.Add(list[num-1]);
            list.RemoveAt(num-1);
        }
        for(int i =0;i<list.Count;i++){
            if(i<list.Count-1){System.Console.Write(list[i]+" ");}
            else{
                System.Console.Write(list[i]);
            }
            
        }
        
    }
}

方法二

using System;
    class Program

    {

        static void Main(string[] args)

        {

            int n = int.Parse(Console.ReadLine());
            int[] arr = new int[n];
            string[] strArr = Console.ReadLine().Split();
            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
           {
                arr[i] = int.Parse(strArr[i]);
            }          
            for (int i = 0; i < k; i++)

            {
                double x = double.Parse(Console.ReadLine());

                int temp = arr[x - 1];

                for (int j = x; j < n; j++)

                {

                    arr[j - 1] = arr[j];

                }

                arr[n - 1] = temp;

            }

            Console.WriteLine(string.Join(" ", arr));

        }

    }

public class Program{
 static void Main(string[] args){
     float n = System.Convert.ToInt32(System.Console.ReadLine());
     System.Console.Write("The area for the circle of radius {0} is {1}",n.ToString("0.0"),n*n*3.14159);
 }
}

public class Program{

    static void Main(string[]args){

        string i =System.Console.ReadLine();

        string[] isr =i.Split(new char[]{' '});

        long  money=1;

        int Dianya = int.Parse(isr[0]);

        int Du =int.Parse(isr[1]);

        if(Dianya<=0||Du<=0){System.Console.WriteLine("invalid value");}

        else if(Dianya<=1000&&Dianya>=0){

            if(Du<=180&&Du>0){money=0.52l*Du;}

            else if(Du>180&&Du<=280){money=0.57l*Du;}

            if(Du>280) {money=Du*0.82;}

            System.Console.Write("{0}",money.ToString("0.00"));

        }

         else if(Dianya>=1000&&Dianya<=10000){

            if(Du<=180&&Du>0){money=0.47*Du;}

            else if(Du>180&&Du==280){money=0.52*Du;}

            else if (Du>280){money=0.77*Du;}

            System.Console.Write("{0}",money.ToString("0.00"));

        }

    }

}

方法一

10的9次方 用long 类型就可以满分了

using System;

namespace ConsoleApp

{

    class Program

    {

        static void Main(string[] args)

        {

            string[] inputs = Console.ReadLine().Split(' ');

            long x = Convert.ToInt32(inputs[0]);

            long y = Convert.ToInt32(inputs[1]);

            Console.WriteLine(x * y / Gcd(x, y));

        }

        static long Gcd( long x, long y)

        {

            return y == 0 ? x : Gcd(y, x % y);

        }

    }

}

方法二


public class Program{
    static void Main(string[] args){
        int c1=0,c2=0,ys=1,x,y;
        string i =System.Console.ReadLine();
        string[] ins = i.Split(new char[]{' '});
        int a = int.Parse(ins[0]);
        int b = int.Parse(ins[1]);
        int m =b;
        for(;;m--){
            if(a%m==0&&b%m==0){
                x=m;break;
            }
        }
        y=a*b/x;
        System.Console.WriteLine(y);
    }
}

internal class BanBusiness
{
    public string bankName="中国银行";
    private string name;
    private int password;
    private double balance;
    public void welcome()
    {
        System.Console.WriteLine(bankName+"欢迎您的到来!");
    }
    public void welcomeNext()
    {
        System.Console.WriteLine("请收好您的证件和物品,欢迎您下次光临!");
    }
    public BanBusiness(){}
    public BanBusiness(string name,int password)
    {
        this.name=name;
        this.password=password;
        this.balance=0;
    }
    public void deposit(int password,double change)
    {
        if(password!=this.password)
        {
            System.Console.WriteLine("您的密码错误!");
        }
        else
        {
            this.balance+=change;
            System.Console.WriteLine("您的余额有{0}元。",this.balance.ToString("0.0"));
        }
    }
    public void withdraw(int password,double change)
    {
        if(password!=this.password)
        {
            System.Console.WriteLine("您的密码错误!");
        }
        else if(this.balance<change)
        {
            System.Console.WriteLine("您的余额不足!");
        }
        else
        {
            this.balance-=change;
            System.Console.WriteLine("请取走钞票,您的余额还有{0}元。",this.balance.ToString("0.0"));
        }
        
    }
}
internal class Program{
    

 static void Main(string[]args)
{
    BanBusiness user=new BanBusiness();
    user.welcome();
    string inn = System.Console.ReadLine();
    string[]str=inn.Split(new char[]{' '});
    BanBusiness user1=new BanBusiness(str[0],int.Parse(str[1]));
     
     string inn1 = System.Console.ReadLine();
     string[]str1=inn1.Split(new char[]{' '});
    user1.deposit(int.Parse(str1[0]),double.Parse(str1[1]));
    
    string inn2 = System.Console.ReadLine();
    string[] str2=inn2.Split(new char[]{' '});
     user1.withdraw(int.Parse(str2[0]),double.Parse(str2[1]));
     
    string inn3 = System.Console.ReadLine();
    string[] str3 =inn3.Split(new char[]{' '});
     user1.withdraw(int.Parse(str3[0]),double.Parse(str3[1]));
     
    string inn4 = System.Console.ReadLine();
    string[] str4=inn4.Split(new char[]{' '});
    

    user1.withdraw(int.Parse(str4[0]),double.Parse(str4[1]));
    user.welcomeNext();
 }
} 


class Employee
{
    public int qian;
    public int getSalary(int qian,int a)
    {
        return qian;
    }
}
class Manager:Employee
{
     public int getSalary(int qian)
     {
         this.qian=qian;
         return qian;
     }
}
class Salesman:Employee
{
      public int getSalary(int qian,int tc)
      {
          return qian+tc;
      }
}
class Worker:Employee
{
       public int getSalary(int qian,int tian)
       {
            return qian*tian;
       }
}
class main{
   static void Main(string[]args){
   Manager use1=new Manager();
   Salesman use2=new Salesman();
   Worker use3 =new Worker();
   
   string gz1 = System.Console.ReadLine();
   string gz2 = System.Console.ReadLine();
   string[] str2 = gz2.Split(new char[]{' '});
   string gz3 = System.Console.ReadLine();
   string[] str3 = gz3.Split(new char[]{' '});
   
   System.Console.WriteLine(use1.getSalary(int.Parse(gz1)));
   System.Console.WriteLine(use2.getSalary(int.Parse(str2[0]),int.Parse(str2[1])));
   System.Console.WriteLine(use3.getSalary(int.Parse(str3[0]),int.Parse(str3[1])));
   }
}

abstract class Employee
{
    public int qian,tian,tc;
    public abstract int getSalary();
}
class Manager:Employee{
    public Manager(){}
    protected Manager(int qian){this.qian=qian;}
    public int getSalary(int qian){return qian;}
    public override int getSalary(){throw new System.NotImplementedException();}
}
class Salesman:Employee{
    int qian,tian;
    public Salesman(){}
    protected Salesman(int qian,int tc){this.qian=qian;this.tc=tc;}
    public int getSalary(int qian,int tc){return qian+tc;}
    public override int getSalary(){throw new System.NotImplementedException();}    
}
class Worker:Employee{
    public Worker(){}
    protected Worker(int qian,int tian){this.qian=qian;this.tian=tian;}
    public int getSalary(int qian,int tian){return qian*tian;}
    public override int getSalary(){throw new System.NotImplementedException();}
}
class main{
    static void Main(string[]args){
        Manager u1=new Manager();
        Salesman u2=new Salesman();
        Worker u3=new Worker();
        
        string g1=System.Console.ReadLine();
        string g2=System.Console.ReadLine();
        string[] s2=g2.Split(new char[]{' '});
        string g3=System.Console.ReadLine();
        string[] s3=g3.Split(new char[]{' '});
        
        System.Console.WriteLine(u1.getSalary(int.Parse(g1)));
        System.Console.WriteLine(u2.getSalary(int.Parse(s2[0]),int.Parse(s2[1])));
        System.Console.WriteLine(u3.getSalary(int.Parse(s3[0]),int.Parse(s3[1])));
    }
}

###这题是0分,仅供参考

abstract class Shape{
    public double pai=3.1415926d;
    public abstract double area();
    public abstract double perimeter();
}
class Oval:Shape{
private double cb,db;
    public Oval(double cb,double db){
        this.cb=cb;
        this.db=db;
    }
    public Oval(){this.cb=0;this.db=0;}
    public double area(double cb,double db){return System.Math.Round(cb*db*pai,15);}
    public double perimeter(double cb,double db){
        return 2*pai*System.Math.Sqrt((cb*cb+db*db)/2);
    }
    public string toString(){
        return "Oval(a:"+cb.ToString("0.0")+",b:"+db.ToString("0.0")+")";
    }
    public override double area(){throw new System.NotImplementedException();}
    public override double perimeter(){throw new System.NotImplementedException();}
    
}
class pro{
    static void Main(string[]args){
        string s =System.Console.ReadLine();
        string[] str=s.Split(new char[]{' '});
        Oval aa=new Oval(double.Parse(str[0]),double.Parse(str[1]));
        System.Console.WriteLine("The area of "+aa.toString()+" is "+(aa.area(int.Parse(str[0]),int.Parse(str[1]))));
        System.Console.WriteLine("The perimeterof "+aa.toString()+" is "+(aa.perimeter(int.Parse(str[0]),int.Parse(str[1]))));
    }
}

###这题在vs上运行答案是对的,但是在pta上小数点保留是错的


using System.Collections;

class pro{
    static void Main(string[] args){
        int k =System.Convert.ToInt32(System.Console.ReadLine());
        string i = System.Console.ReadLine();
        string[] s = i.Split(new char[]{','});
        Queue list=new Queue();
        for(int m =0;m<s.Length;m++){
            list.Enqueue(s[m]);
        }
        int f = 1;
        while(list.Count>=2){
            if(f==k){System.Console.Write(list.Dequeue()+",");
                    f=1;}
            else{
                list.Enqueue(list.Dequeue());
                f++;
            }
        }
        System.Console.Write(list.Dequeue());
    }
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值