Input-Output Techniques: In all programming competition, or more specially, in all useful program, you require to read in input and process it. Though, the input data can be as horrible as possible, and this can be very troublesome to the parse.
If you spend too much time in the coding how to parse the input proficiently and you are utilizing C/C++ as your programming language, then this tip is especially for you. Let us see an illustration:
How to read the following input: 1 2 2 3 1 2 3 1 2 The fastest method to do it is:
#include <stdio.h> int N; void main() { while(scanf("%d",&N==1)){ process N… } }
There are N lines; each line always begins with character '0' followed by '.', then unknown number of digits x, lastly the line always terminated by three dots "...".
N 0.xxxx...
The fastest method to do it is:
#include <stdio.h> char digits[100]; void main() { scanf("%d",&N); for (i=0; i<N; i++) { scanf("0.%[0-9]...",&digits); // surprised? printf("the digits are 0.%s\n",digits); } }
This is the trick which many C/C++ programmers do not aware of. Why we state C++ while scanf/printf is a standard C I/O routine? This is since most of the C++ programmers "forcing" themselves to employ cin/cout all the time, devoid of realizing that scanf/printf can still be employed within all C++ programs. Advanced use of printf() and scanf():
Such who have forgotten the advanced use of printf() and scanf(), remind the following illustrations:
scanf("%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]",&line); //line is a string
This scanf() function takes just upper-case letters as input to line and any other characters other than A….Z terminates the string. Likewise the following scanf() will behave like gets():
scanf("%[^\n]",line); //line is a string
Learn the default terminating characters for the scanf(). Using new line with scanf():
When the content of a file (input.txt) is
abc def
And the following program is performed to take input from file:
char input[100],ch; void main(void) { freopen("input.txt","rb",stdin); scanf("%s",&input); scanf("%c",&ch); }The following is a small modification to code: char input[100],ch; void main(void) { freopen("input.txt","rb",stdin); scanf("%s\n",&input); scanf("%c",&ch); }
What will be their respective value? The value of ch will be '\n' for the first code and 'd' for second code.Be careful about using gets() and scanf() together:
You must as well be careful about using gets() and scanf() in similar program. Test it with the following scenario. Code is as shown below:
scanf("%s\n",&dummy); gets(name); And the input file is: ABCDEF bbbbbXXX
What do you obtain as the value of name? "XXX" or "bbbbbXXX" (Here, ‘b’ signifies blank or space)
Latest technology based Programming Languages Online Tutoring Assistance
Tutors, at the www.tutorsglobe.com, take pledge to provide full satisfaction and assurance in Programming Languages help via online tutoring. Students are getting 100% satisfaction by online tutors across the globe. Here you can get homework help for Programming Languages, project ideas and tutorials. We provide email based Programming Languages help. You can join us to ask queries 24x7 with live, experienced and qualified online tutors specialized in Programming Languages. Through Online Tutoring, you would be able to complete your homework or assignments at your home. Tutors at the TutorsGlobe are committed to provide the best quality online tutoring assistance for Programming Languages Homework help and assignment help services. They use their experience, as they have solved thousands of the Programming Languages assignments, which may help you to solve your complex issues of Programming Languages. TutorsGlobe assure for the best quality compliance to your homework. Compromise with quality is not in our dictionary. If we feel that we are not able to provide the homework help as per the deadline or given instruction by the student, we refund the money of the student without any delay.
www.tutorsglobe.com offers reactions of substituent groups homework help, reactions of substituent groups assignment help, online tutoring assistance, organic chemistry solutions by online qualified tutor's help.
tutorsglobe.com immobilization assignment help-homework help by online industrial microbiology tutors
Plants and Related Organisms tutorial all along with the key concepts of Diversity of Life on Earth, Features of Living Things, Origin of Life, Organization of Cells-Prokaryotes and Eukaryotes and Evolution by Endosymbiosis
tutorsglobe.com paulings scale assignment help-homework help by online electronegativity scales tutors
tutorsglobe.com extraction from gold ores assignment help-homework help by online occurrence and principles of extraction of gold tutors
tutorsglobe.com objectives of financial management assignment help-homework help by online financial management tutors
Other Types of Telescopes tutorial all along with the key concepts of Eye Ring, Astronomical Telescope with Image Formed at Near Point, Terrestrial Telescope, Reflector Telescope
Theory and lecture notes of Data Independence all along with the key concepts of data independence, kinds of data Independence, Logical data independence, Physical data independence. Tutorsglobe offers homework help, assignment help and tutor’s assistance on Data Independence.
Theory and lecture notes of Concept of Conditional Probability all along with the key concepts of homework help, assignment help, probability tutors. Tutorsglobe offers homework help, assignment help and tutor’s assistance on Concept of Conditional Probability.
physical and chemical characteristics of alkali metals tutorial all along with the key concepts of alkali metals occurrence, extraction of alkali metals, uses of alkali metals, melting points-boiling points, thermal-electrical conductivity, ionisation energy, ionic character of compounds, lattice energy-hydration energy
www.tutorsglobe.com offers chemical reactivity homework help, chemical reactivity assignment help, online tutoring assistance, organic chemistry solutions by online qualified tutor's help.
Negative Feedback tutorial all along with the key concepts of Benefits of Negative Feedback, Gain Stability, Decreased Distortion, Feedback over Several Stages, Forms of Negative Feedback, Shunt-Derived Series-Fed Voltage Feedback, Current-Series Feedback Amplifier
tutorsglobe.com stages of short-run law assignment help-homework help by online classification of production function tutors
Classification of algae tutorial all along with the key concepts of PROKARYOTIC ALGAE, EUKARYOTIC ALGAE, Division Cyanophyta, Division Chlorophyta, Division Phaeophyta, Division Rhodophyta, Division Xanthophyta, Division Euglenophyta, Division Dinophyta, Division Bacillariophyta
Theory and lecture notes of Reactive Circuit Elements and Capacitive Reactance all along with the key concepts of reactive circuit elements, capacitive reactance, inductive reactance, sinusoidal current and voltage. Tutorsglobe offers homework help, assignment help and tutor’s assistance on Reactive Circuit Elements and Capacitive Reactance.
1954469
Questions Asked
3689
Tutors
1495416
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!