×

# Are C strings faster than C++ string object?

 1 A very weird thing I faced today in Cook Off, my same solution got AC when I used char str[MAX] than using string str, is C string faster than C++ string object? asked 24 Apr '17, 00:03 1.1k●13 accept rate: 20%

 5 It is because complexity of str1=str1+'a'; is O(n). Use str1+='a'; answered 24 Apr '17, 00:19 923●13 accept rate: 11% Okay, thank you for this,It costed me 4 TLE and penalties :( (24 Apr '17, 00:34) 2 Its ok ! Dude ! Believe me Lessons learnt this way will never be forgotten ! (24 Apr '17, 00:59) Lol, ask me. I got penalty for using "n/2 *(2 x a+(n-1) x d) instead of (n x (2 x a+(n-1) x d)/2 (24 Apr '17, 01:17) 3 @pankajkhan that is very true XD (24 Apr '17, 01:24) meooow ♦6★ 1 @dushsingh1995 exactly :| @vijju123 for a moment I was thinking O(lg n) or O(1) solution isn't possible then why TLE. :| (24 Apr '17, 01:31)
 1 for(ll i=0;i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,357
×555

question asked: 24 Apr '17, 00:03

question was seen: 413 times

last updated: 24 Apr '17, 01:32