题解 | 学生基本信息输入输出

学生基本信息输入输出

https://www.nowcoder.com/practice/58b6a69b4bf943b49d2cd3c15770b9fd

#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;
	string i, a, b, c;
	i = s.substr(0, s.find(';'));
	s.erase(0, s.find(';') + 1);
	a = s.substr(0, s.find(','));
	//cout << a.size() - a.find('.')-2;
	if ((int)a.find('.') == -1) {
		a += ".00";
	}
	else {
		if ((int)a.size() - a.find('.') - 2 >= 2) {
			if (a[a.find('.') + 3] > '4') {
				if (a[a.find('.') + 2] == '9') {
					a[a.find('.') + 1]++;
					a[a.find('.') + 2] = '0';
					a.erase(a.find('.') + 3);
				}
				else {
					a[a.find('.') + 2]++;
					a.erase(a.find('.') + 3);
				}
			}
			else {
				a.erase(a.find('.') + 3);
			}
		}
	}
	s.erase(0, s.find(',') + 1);
	b = s.substr(0, s.find(','));
	if ((int)b.find('.') == -1) {
		b += ".00";
	}
	else if((int)b.size() - b.find('.') - 2 >= 2) {
		if (b[b.find('.') + 3] > '4') {
			if (b[b.find('.') + 2] == '9') {
				b[b.find('.') + 1]++;
				b[b.find('.') + 2] = '0';
				b.erase(b.find('.') + 3);
			}
			else {
				b[b.find('.') + 2]++;
				b.erase(b.find('.') + 3);
			}
		}
		else {
			b.erase(b.find('.') + 3);
		}
	}
	s.erase(0, s.find(',') + 1);
	if ((int)s.find('.') == -1) {
		s += ".00";
	}
	else if((int)s.size() - s.find('.') - 2 >= 2) {
		if (s[s.find('.') + 3] > '4') {
			if (s[s.find('.') + 2] == '9') {
				s[s.find('.') + 1]++;
				s[s.find('.') + 2] = '0';
				s.erase(s.find('.') + 3);
			}
			else {
				s[s.find('.') + 2]++;
				s.erase(s.find('.') + 3);
			}
		}
		else {
			s.erase(s.find('.') + 3);
		}
	}
	cout << "The each subject score of No. " << i << " is " << a;
	cout << ", ";
	cout << b;
	cout << ", ";
	cout << s;
	cout << "." << endl;
}

// 64 位输出请用 printf("%lld")

全部评论

相关推荐

11-03 18:50
门头沟学院 Java
迷茫的大四🐶:问就是马上到,一周五天,6个月以上,全国可飞
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务