C#7-6 混合类型数据格式化输入 (5 分)

本题要求编写程序,顺序读入浮点数1、整数、字符、浮点数2,再按照字符、整数、浮点数1、浮点数2的顺序输出。

输入格式:

输入在一行中顺序给出浮点数1、整数、字符、浮点数2,其间以1个空格分隔。

输出格式:

在一行中按照字符、整数、浮点数1、浮点数2的顺序输出,其中浮点数保留小数点后2位。

输入样例:

2.12 88 c 4.7

输出样例:

c 88 2.12 4.70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PTA
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            double a = double.Parse(s.Substring(0, s.IndexOf(" ")));//a是浮点数1
            a = Math.Round(a, 2);
            string s1 = s.Substring(s.IndexOf(" ")+1);
            //Console.WriteLine(s1);
            int b = Int32.Parse(s1.Substring(0, s1.IndexOf(" ")));//b是整数
            string s2 = s1.Substring(s1.IndexOf(" ")+1);
            //Console.WriteLine(s2);
            char c = s2[0];
            double d = double.Parse(s2.Substring(2));
            d = Math.Round(d, 2);
            Console.Write(c + " " + b + " " + a.ToString("#0.00") +" "+d.ToString("#0.00"));
        }
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值