About Problem B in abc367

Правка en3, от He_XY, 2024-08-18 07:28:41

AtCoder Beginner Contest 367 is over. Problem B this time is very good.

It says: Give you a real number to the third decimal place. Delete the unnecessary zeros and '.' .

I saw many participants using string and .pop_back(), and other ways like this:

int main(){
	cin>>s;
	int n=s.size();
	if(s[n-1]=='0')
	{
		n--;
		if(s[n-1]=='0')
		{
			n--;
			if(s[n-1]=='0')
				n-=2;
		}
	}
	for(int i=0;i<n;i++) cout<<s[i];
	return 0;
}

but I found a simpler way:

Just input and then output (C++), because it can help you delete them.

Code:

#include<bits/stdc++.h>
using namespace std;
double a;
int main(){
	cin>>a;
	cout<<a<<endl;
	return 0;
}

This takes you less time in the contest.

Thank you for reading!

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский He_XY 2024-08-18 07:28:41 254
en2 Английский He_XY 2024-08-18 07:11:02 26 Tiny change: 'e contest.' -> 'e contest.\n\nThank you for reading!'
en1 Английский He_XY 2024-08-18 06:54:06 590 Initial revision (published)