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

Автор Fk_Viper, 11 лет назад, По-английски

I am a new entrant here.Please let me know how to read input files? Thanks

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

»
11 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

There is no input files. Input and output are standart, e.g. console.

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится -10 Проголосовать: не нравится

    Can you tell me how the contribution is calculated here?

    • »
      »
      »
      11 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      get more voteups in your comments then your contribution will get higher

      get more votedowns in your comments then your contribution will get lower

      for new users the contribution which have a few comments will change with a large extent when the users become elder thier contribution will change with a low extent

      • »
        »
        »
        »
        11 лет назад, # ^ |
          Проголосовать: нравится +7 Проголосовать: не нравится

        So,People prefer to vote down here as i see....nice...

        • »
          »
          »
          »
          »
          4 года назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          Well, if you post something that they dont interested, they usually downvote. Dont worry about that, just keep in mind what you need to know from the other people who are answer your post

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    There are some questions in the problemset that require file i/o. One such contest that I found is :https://codeforces.com/contest/234

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      include <stdio.h>

      include <stdlib.h>

      int main()

      {

      FILE *wrp;

      int n;

      char data[100];

      char num[5];

      wrp = fopen("input.txt","r");

      char readchar;

      int i=0;

      int jl = 0;

      int x=0;

      while (1==1) {

      readchar = fgetc(wrp);
      
      if (readchar == EOF) {
      
          break;
      
      }

      if (readchar != '\n') {

      if (x==0) {
      
      num[jl] = readchar;
      
      jl++;
      
      } else {
      
      data[i] = readchar;
      i++;
      
      }

      } else { x=1; } }

      fclose(wrp);

      n = atoi(num);

      wrp = fopen("output.txt","w");

      int j=0;

      while(j<n/2) {

      if (data[j] == 'L') {

      char num1[3];

      char num2[3];

      itoa(j+1,num1,10);

      itoa(j+(n/2)+1,num2,10);

      fputs(num1,wrp);

      fputs(" ",wrp);

      fputs(num2,wrp);

      fputs("\n",wrp);

      } else {

      if (data[j+(n/2)] == 'L') {

      char num1[3];

      char num2[3];

      itoa(j+1,num1,10);

      itoa(j+(n/2)+1,num2,10);

      fputs(num2,wrp);

      fputs(" ",wrp);

      fputs(num1,wrp);

      fputs("\n",wrp);

      } else {

      char num1[3];

      char num2[3];

      itoa(j+1,num1,10);

      itoa(j+(n/2)+1,num2,10);

      fputs(num1,wrp);

      fputs(" ",wrp);

      fputs(num2,wrp);

      fputs("\n",wrp);

      }

      }

      j++;

      }

      fclose(wrp);

      return 0;

      }

      sir in this contest also we are reading and writing in file i am beginner not able to understand how to write opening files in ICPC contest please help me out

      wrp = fopen("output.txt","r");

      wrp = fopen("output.txt","w");

»
11 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

As I can see you managed to read from stdin.

Sometimes in gym you need read from file.
The easiest way to do it in C++ is to use freopen

freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);

And then read, as from stdin

»
11 лет назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

In some contests, you have to read the input from "input.txt" and write your output in "output.txt", e.g. Codeforces Round 155 (Div. 2). In these situations you can use #include <fstream>as easy as cin/cout (#include <iostream>).

Just write #include <fstream> at the top of your code and define some iofstream variables such as fin and fout:

ifstream fin("input.txt");
ofstream fout("output.txt");

Now you can use them like cin/cout:

fin >> n;
fout << n;
»
4 года назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

I think you can use freopen

Code