Блог пользователя sayeed_1999

Автор sayeed_1999, история, 3 года назад, По-английски

Question:

You are given a sentence as a string. The sentence may have more than one space in between its words and also extra space at the beginning and end of the string. You have to print only the first letters of each word of the given sentence as a string.

Example test cases:

input:
abc def   ghi
output:
adg

input:
  abc   def z
output:
adz

Algorithm:-

string s; cin >> s; // take user sentence input

s.insert(0, ' '); // insert an extra space at the begining of string so that all the words surely have a space before it!

for(int i=1; s[i]; i++)
{
  if( s[i-1]==' ' && s[i]!=' ' ) cout << s[i];
}

tricky implementation, wasn't it?!

Полный текст и комментарии »

  • Проголосовать: нравится
  • -20
  • Проголосовать: не нравится

Автор sayeed_1999, история, 4 года назад, По-английски

The algorithm computes from one source vertex the whole thing.

If i want to detect negative cycles in a graph using bellman ford, if i assume vertex 1 as the source, and no edge comes out of the vertex 1 in that test set, it wont work.

how will you consider source vertex in these cases... to detect negative cycles

Asking for solutions..

Полный текст и комментарии »

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится