You are not logged in. Please login at www.codechef.com to post your questions!

×

CHKSTR - Editorial

PROBLEM LINK :

contest

practice

Author : Vibhor Gupta

Tester : Vibhor Gupta

Editorialist : Vibhor Gupta

DIFFICULTY :

Medium-Hard

PREREQUISITES :

stringstream function

PROBLEM :

Rahul ha been given a string containing space separated integers. He does not know how many integers are in the string.

He has also been given 2 integers a,b. He has to make a fibonacci type of sequence with it. i.e nth term is sum of (n-1)th term and (n-2)th term.

Finally he has to calculate the sum of the nth integer in the above sequence for every integer n in the string. As the output can be large, print the answer modulo 10^9 + 7

Flawed Code :

#include

#define gl(x) getline(cin,x);

using namespace std;

long long fib[1000000];

int main(){

int t;cin>>t;

while(tc--){

int a,b;cin>>a>>b;

fib[0]=a;fib1=b;

for(int i=2;i!=1000000;i++) fib[i] = (fib[i-1]+fib[i-2])%mod;

string s;cin>>s;

stringstream ss;

int x;

int sum=0;

while(ss>>x)sum += fib[x];

printf("%d",sum);}

EXPLANATION :

This question was quite simple, the main challenge was to take input of an unknown number of integers.

The normal cin could not be used as it would eat up the next test case also.

This problem was solved using the Stringstream function.

The corrected code can be view at, Corrected Solution

This question is marked "community wiki".

asked 30 Mar '16, 22:13

vibhor3gupta's gravatar image

4★vibhor3gupta
111
accept rate: 0%

edited 01 Apr '16, 16:43

admin's gravatar image

0★admin ♦♦
19.7k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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:

×15,482
×1,236
×815
×6
×1

question asked: 30 Mar '16, 22:13

question was seen: 836 times

last updated: 01 Apr '16, 16:43