I want to generate multiple files in c language .. like Update prefix then next name like Update01 Update02 update03 etc....
Can we give dynamicaly name to files in c????
Help understanding this compilation error
#include<stdio.h>
void show()
{
int a[100],b[100],x,y=1,z,m,k,w=0,h,i,t=1,s=0;
scanf("%d",&x);
for(i=0;i<x;i++)
scanf("%d,%d",&a[i],&b[i]);
while( y<=x)
{
z=a[i];
while(z<=b[i])
{k=z;
while(k!=0)
{
h=k/10;
k=k%10;
if(!(h==4)&&!(h==7))
t=0;}
if(t!=0)
{k=z;
while(k!=0)
{k=k%10;
s++;
}
}
if(s==4||s==7)
w++;
z++;
}
m=w%100000007;
printf("\n%d",m);
y++;
}
}
``So I submitted this code for Lucky2 Problem but a compilation error showed up saying:
/usr/lib/gcc/i486-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: In function _start':
(.text+0x18): undefined reference to
main'
collect2: error: ld returned 1 exit status
Can anyone plz explain it to me...I mean what have I done wrong here?
Compilation Error : C++ code taken as C
Hi all, I am participating the the September Challenge 2012. When I am submitting my program in c++, I am getting the following compilation error :-
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o: In function _start': /home/aurel32/tmp/glibc/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to
main' collect2: ld returned 1 exit status
When I go to My Submissions, it shows me that I submitted the code in C, but while submitting I always select "C++(gcc 4.3.2)". Moreover, I have tried with the extension .cpp as well as .cc, but it didn't help. The code is compiling perfectly fine in my machine(having gcc 4.4.6).
It would be great if anyone of you guide me in what's the correct way of submitting the code in c++. I have already gone through the complete FAQ twice, but didn't find any reference to such a problem.
Regards,
Jayant
Compilation error using iostream.h and conio.h
I wrote my first program in c++ and ended up with this compilation error, please help me out.
In file included from /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/backward/iostream.h:31, from prog.cpp:1: /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. prog.cpp:2:18: error: conio.h: No such file or directory prog.cpp:11:4: warning: no newline at end of file prog.cpp:3: error: '::main' must return 'int' prog.cpp: In function 'int main()': prog.cpp:4: error: 'clrscr' was not declared in this scope prog.cpp:10: error: 'getch' was not declared in this scope
getting time limit exceed
I have found a constraints like this -1 <= i <= 10^9 in an Online competetion . so how can i take such a very large integer or store it. someone please help me .thanks in advance.
Chef team Sigsev error
qstn http://www.codechef.com/problems/CHEFTEAM I am getting sigsegv error please check http://www.codechef.com/viewsolution/4599164
Wrong answer on codeforces but correct answer on Ideone and on my PC!
This is the question ive been doing
QUESTION : http://codeforces.com/contest/460/problem/B
MY SOLUTION : http://ideone.com/i6fiRc
Codeforces says that on testcase 8 which is 5 9998 9998 my code gives the output as 0 but on my PC and on Ideone it gives the required output which is 1 1933785806
How is this possible???
Spoj: GAMES
I'm trying to solve http://www.spoj.com/problems/GAMES/ this problem on SPOJ, but it is giving WA everytime, Can you help me about what I'm missing? Thanks Here's my code:
#include <iostream>
using namespace std;
define ll long long int
ll gcd(ll a,ll b) { if(b==0) return a; else return gcd(b,a%b); }
int main () {
int t;
scanf("%d",&t);
while(t--) {
double avg;
cin>>avg;
ll l=1;
int i; ll k;
double k1;
for(i=1;i<=5;i++)
{
k=0;
k1=0.0;
l=l*10;
k=avg*l;
// cout<<k<<endl;
k1=avg*l;
// cout<<k1<<endl;
if(k1-k<=0.00001) break;
}
ll g=gcd(k,l);
cout<<l/g<<endl;
}
return 0; }
sum query july cookoff
why am i getting a runtime error ??
problem page:-http://www.codechef.com/problems/RRSUM/
my solution:-http://www.codechef.com/viewsolution/4598396
Reading different variable from a file..
suppose file content is ID=name ID1=name1 ID2=name2 . . . IDn=namen
how to read and store ID values and name values in different arrays using C..?
Graph Algorithms in Competitive Programming
Is graph an important topic in Competitive Programming? If yes, what are the algorithms that are frequently asked ?
EDIT :- I did googling and found some awesome stuff on graphs . I am sharing it with you all. Hope it might be helpful.
1 : Hopcroft–Karp algorithm : An algorithm that takes as input a bipartite graph and produces as output a maximum cardinality matching.
2 : Ford–Fulkerson algorithm : Maximum possible flow from source to destination.
3 : Breadth-first search : Searching or traversing in a graph
4 : Depth-first search : Traversing or searching tree or graph data structures
5 : Floyd-Warshall ALgorithm : Shortest path algorithm
6 : Dijkstra's algorithm : Single-source shortest-path problem when all edges have non-negative weights.
7 : Prim's algorithm : Minimum Spanning Tree
8 : Kosaraju's algorithm : Problem of finding connected components
9 : Hungarian algorithm : Assignment problem
10 : Topological sorting : Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering.
11 : Minimum spanning tree : An edge-weighted graph is a graph where we associate weights or costs with each edge. A minimum spanning tree (MST) of an edge-weighted graph is a spanning tree whose weight (the sum of the weights of its edges) is no larger than the weight of any other spanning tree.
12 : Priority queue : In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.
13 : Kruskal's algorithm : Minimum Spanning Tree Algorithm
14 : PageRank algorithm : The Mathematics of Google Search
15 : Coloring algorithm : It is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints.
findind fibonacci series till 100000
I am getting segmentation fault (SIGSEGV) while finding fibonacci series till 100000.
The question is fibonum of peer section.Here is the link
http://www.codechef.com/problems/JMI04
And, this is the link to my code
1.using array simply
http://www.codechef.com/viewsolution/4603245
2.using recursion
Unknown behavior of the C++ problem
include <iostream>
using namespace std;
int main() {
double a;
cin >> a;
a=a-(int)a;
a=a*10000;
cout << (int)a;
return 0;
}
when i input 1.1500 then i get input 1499 but the output should be 1500
what is a >?= b
where a and b are variables. I don't understand this operator.. i've seen it in a solution... what does it do? and how to use it?
NUMGAME2 - Editorial
How did mugurelionut & ACRush became so great at competitive programming?
I just wonder how these both great programmers became so great at programming. How did they started programming, and what makes them so unique.
I see,they write 200-300 lines of codes for challenge problem to get that 1 point. And in all contests they finish in top 5. For me it's just like OMG :O
And how old are both of them?(and how much experience)
Learning Greedy !
I am trying to learn greedy and so i am solving some problems./ I have tried to code Greedy for http://www.codechef.com/problems/FGFS ,But getting wrong answer. Can anyone tell why? My solution is http://www.codechef.com/status/FGFS,vippu95
DP problem help
What can be the optimized algorithm to solve this problem ?
Given a matrix with M rows and N columns (M x N). In each cell there's a number of apples. You start from the upper-left corner of the matrix. You can go down or right one cell. You need to arrive to the bottom-right corner. Then you need to go back to the upper-left cell by going each step one cell left or up. Find the maximum number of apples you can collect.When you pass through a cell - you collect all the apples left there.
Restrictions: 1 < N, M <= 50 ; each cell contains between 0 and 1000 apples inclusive
RANDOM NUMBER GENERATION
How can I generate a random matrix of order m by n using rand() in C++ with a specified range?
Why this code is not working for all the input?
Here is the question
The first line contains the string s which Steve Jobs' ghost types. The second line contains an integer n (1<=n<=100) which is the number of words in the dictionary. Then follow n lines which are the words on the dictionary, one on each line. All the lines have lengths of 1 to 100 characters inclusively, and consist of lowercase English letters only.
Output
If s is not the beginning of any of n words in the dictionary, print s. Otherwise, print the lexicographically lowest word beginning with s.
The lexicographical order is the order of words in a dictionary.
Sample test(s)
Input
next 2 nextpermutation nextelement
Output
nextelement
Here is my Code
int main()
{
char wo[30],fs[30],dic[100][30];
int mt[100],dicln[100];
int i, cnt, wordc,k=0,j,temp,x,t1;
scanf("%s",wo);
scanf("%d",&cnt);
wordc = strlen(wo);
for(i = 0 ; i < cnt; i++)
{
scanf("%s",dic[i]);
if(strncmp(dic[i],wo,wordc) == 0)
{
mt[k] = i;
k++;
}
}
temp = mt[0];
strcpy(fs, dic[temp]);
for(i = 0; i < k-1; i ++)
{
temp = mt[i];
if(strlen(dic[temp+1]) == strlen(dic[temp]))
{
for(j = wordc+1; j <= strlen(dic[temp]) ; j++)
{
t1 = strncmp(dic[temp+1],dic[temp],j);
if(t1 < 0 )
strcpy(fs, dic[temp+1]);
}
}
else if(strlen(dic[temp+1]) < strlen(dic[temp]))
{
strcpy(fs, dic[temp+1]);
}
}
if(k == 0)
printf("%s",wo);
else
printf("%s",fs);
return 0;
}
For this output I got 70 out of 100. So I want to know for which input the code will fail.
I don't need new code, just need modification in my code for those input.
Thanks in adv.