CFR 697 B. Barnicle ( Ad hoc )
Problem - B - Codeforces
Silly I really failed this one in the real test. Should have calmed down and check all cases manually since there weren't many to come up.
void solve(){ string s; cin >> s; int dec_pos = s.size(); for( int i = 0; i < s.size(); ++i ) if( s[ i ] == '.' ) dec_pos = i; vi numbers, num_pos; for( int i = 0; i < s.size(); ++i ){ if( s[ i ] == '.' ) continue; if( s[ i ] == 'e' ) break; numbers.push_back( s[ i ] - '0' ); num_pos.push_back( i ); } for( int i = numbers.size() - 1; i >= 0; --i ){ if( numbers[ i ] != 0 or num_pos[ i ] < dec_pos ) break; else numbers.pop_back(); } if( numbers.empty() ){ cout << 0 << "\n"; return; } int p_cnt = 0; for( int i = 0; i < s.size(); ++i ){ if( s[ i ] != 'e' ) continue; for( int j = i + 1; j < s.size(); ++j ) p_cnt = p_cnt * 10 + s[ j ] - '0'; break; } if( numbers.size() == p_cnt + 1 ){ for( int num : numbers ) cout << num; return; } if( numbers.size() < p_cnt + 1 ){ for( int num : numbers ) cout << num; for( int i = 0; i < p_cnt + 1 - numbers.size(); ++i ) cout << 0; return; } if( numbers.size() > p_cnt + 1 ){ for( int i = 0; i <= p_cnt; ++i ) cout << numbers[ i ]; cout << '.'; for( int i = p_cnt + 1; i < numbers.size(); ++i ) cout << numbers[ i ]; return; } }