< Back to forum

CHEFPDIG codechef

Question Link: https://www.codechef.com/problems/CHEFPDIG

I am having problem to take input that large number of size10^100000, otherwise i can do it. Please tell me how to take that much large number into consideration.

Actually this is what i was doing. i was using getche(although its not a STL function) and then counting the frequency of the digits. But, the if statement at the last of the program is not executing. Please suggest any better method to take input the number. 

#include<stdio.h>
#include<conio.h>
int main()
{
	char p;
	int i,c=0;
	static int arr[10];
	do
	{	p=getche();    //using getche to take input that large no.
		if(p!='\n')
			arr[p]++;
	}
	while(p!='\r');    //out of the loop after i press enter
    if(arr[6]>=1)
    { 
.
.
.
.
}

 

Asked by: Samrat_De on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




1 Answer(s)

avatar

It is not necessary to take input as an intger.So if you are using c++ then input the number as string and then use that string for further operation.

#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL); //include this line for fast input/output in c++
  int t;
  cin>>t; //use cin to take input and cout for output
  string n;
  while(t--)
  {
	cin>>n;
        //your code
  }
  return 0;
}

 

Shubham_Kumar_Gupta last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.