c:
#include<stdio.h>
int main()
{
float b,c,d;
int a;
scanf("%d;%f,%f,%f",&a,&b,&c,&d);
printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n",a,b,c,d);
}
注:%.f不要忘记点;输出字段可以复制,以免格式出错,类似于两个空格这种;
c++:
#include<bits/stdc++.h>
using namespace std;
int main()
{
float b,c,d;
int a;
char ch ;
cin>>a>>ch>>b>>ch>>c>>ch>>d;
cout << fixed;/*用小数点输出而非科学计数法*/
cout << "The each subject score of No. "<<a<<setprecision(2)<<" is "<<
b<<", "<<c<<", "<<d<<".";
}
注:cout中用setprecision表示输出精度;cout<<fixed看注释;用cin输入浮点数,前面要有char;、
Java:
import java.io.*;
public class Main{
public static void main(String[]args)throws IOException
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String[]s=bf.readLine().split("[;,]");
double a=Double.parseDouble(s[1]);
double b=Double.parseDouble(s[2]);
double c=Double.parseDouble(s[3]);
System.out.printf("The each subject score of No. %s is %.2f, %.2f, %.2f.",s[0],a,b,c);
}
}
注:输出的%s;split后面的;