열 #

2016-11-07 1 views
0

c를이 같은 TXT에 데이터가 0,0,6열 #

개구리, 0010011111004000,5

개구리, 0010011111104000,5

선택한 열의 0 수를 계산해야합니다. 예를 들어 첫 번째 열에는 3 개의 0이 있습니다.

여기 내 코드는 지금까지 있습니다 :이를 해결하기위한

 //data patch 
     string[] tekst = File.ReadAllLines(@"C:\zoo.txt"); 


     //full of array 
     string[] tablica = tekst; 



     for(int s=0;s<tablica.Length;s++) 
     { 
      Console.WriteLine(tablica[s]); 
     } 

     //----------------Show all of array---------------------------// 


     //----------------Giv a number of column-----------------//// 
     Console.WriteLine("Podaj kolumne"); 

     int a = Convert.ToInt32(Console.ReadLine()); 

     //Console.WriteLine("Podaj wiersz"); 

     //int b = Convert.ToInt32(Console.ReadLine()); 

     int n = tablica.Length; 

     int m = tablica[a].Split(',').Length; 

     string[,] liczby = new string[n, m]; 

     for (int j = 0; j < n; j++) 
     { 
      int suma = 0; 
      for (int i = 0; i < m; i++) 
      { 
       //somethink should be here 

      } 

     } 

어떤 아이디어?

+0

시도해 보셨습니까? 무슨 문제 있니? – astidham2003

+0

텍스트를 텍스트가 아닌 텍스트로 포함하십시오. –

+0

나는이 0을 세는 방법을 모르겠다.()에 대해 두 번째를 넣고 txt를 텍스트로 추가 할 생각이 없다. – Domi

답변

0

시도 :

//data patch 
string[] tekst = File.ReadAllLines(@"C:\zoo.txt"); 


//full of array - you allready have a string[], no need for a new one 
//string[] tablica = tekst; 



for(int s=0;s<tekst.Length;s++) 
{ 
    Console.WriteLine(tekst[s]); 
} 

//----------------Show all of array---------------------------// 


//----------------Giv a number of column-----------------//// 
// try to use names with some meaning for variables, for example instead of "a" use "column" for the column 
Console.WriteLine("Podaj kolumne"); 
int column = Convert.ToInt32(Console.ReadLine()); 

// your result for zeros in a given column 
int suma = 0; 

// for each line in your string[] 
foreach (string line in tekst) 
{ 
    // get the line separated by comas 
    string[] lineColumns = line.Split(','); 
    // check if that column is a zero, remember index is base 0 
    if (lineColumns[column-1] == "0") 
     suma++; 
} 

Console.WriteLine(suma); 

편집 : 당신 이름으로 하나로서 첫 번째 열을 고려하지 않는 경우 그냥 배열에 그들이 요청 열이 정말 존재하는지 확인해야합니다, AND, 이 부분을 조정하십시오

lineColumns[column] // instead of lineColumns[column-1] 
+0

sooo so help so much so help !!! :) – Domi