c++ 문자처리 질문
아담
#include iostream
#include fstream
#include string
#include cmath
using namespace std;
int main()
{
char t, s;
string a;
int max, b, c, d, i, j, k, n, cnt[150];
for (i=65; i=90; i++) cnt[i] = 0;
ifstream fin(c:\\input.txt);
ofstream fout(c:\\output.txt);
getline(fin, a);
n = atoi(a.c_str());
max = -99999;
for (i=1; i=n; i++)
{
getline(fin, a);
b = a.length();
for (j=0; j=b-1; j++)
{
s = a.substr(j,1);
if (s = a && s = z) s = s - 32;
if (s = A && s = Z) cnt[s] = cnt[s] + 1;
}
}
for (i=65; i=90; i++)
{
if (cnt[i] = max){
max = cnt[i];
t = i;
}
}
cout t max endl;
return 0;
}
색칠된 부분이 막 에러가 나는데 왜이런지 설명 해주시면 정말 감사하겠어요
-
큰아
배열의 인덱스가 for문의 인덱스와 다르군요 cnt[s]가 아니라 cnt[j]로 하셔야할듯..
-
아인
for문에보니깐 조건에 j=b-1;이라고 해놓앗는데 b에는 쓰레기값이잇는걸로 보이는데요