검색
아하에서 찾은 12건의 질문
- 생활꿀팁생활Q. c 프로그래밍 세그멘테이션 오류계속 세그멘테이션 오류가 뜨는데 어디서 잘못된건지 모르겠습니다ㅜㅜㅜㅜㅜ조언이나 고칠 점 부탁드립니다 ㅜㅜㅜ#include <stdio.h>#include <stdlib.h>void trianglePrint( int **arr, int i, int j){ printf("%d ", arr[i][j]); }void pascalTriangle (int **arr, int i, int j){ for (j = 1; j <= i; j++) { arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j]; trianglePrint(arr, i, j); }}int main(){ int a, i, k, j; scanf("%d", &a); int **arr = NULL; arr = (int *) malloc ( sizeof(int ) * a); arr[0] = (int ) malloc ( sizeof(int) a*a ); for( int k = 1; k < a; k++) { arr[k] = arr[ k-1 ] + a; } for (i = 1; i <= a; i++) { pascalTriangle(arr, i, j); printf("\n"); } return 0;}
- 생활꿀팁생활Q. 자바 스택이용해서 휘위표기법으로 바꾸기 질문좀합니다이면 그전까지 자르기{if(isNum(sb.substring(i-1,i))==0) //그 전이 연산자나 괄호인 경우con_input.add(sb.substring(i,i+1)); //연산자나 괄호 추출else{con_input.add(sb.substring(start, i)); //연산자 전까지의 숫자 추출con_input.add(sb.substring(i,i+1)); //연산자나 괄호 추출start = i+1;}}/*후위식으로 바꾸기*/for(int j = 0; j<con_input.size(); j++){now = con_input.get(j); //하나 추출해서 now에 넣기if(now.contentEquals("+") || now.contentEquals("-") || now.contentEquals("*") || now.contentEquals("/") ||now.contentEquals("(") || now.contentEquals(")")){ //연산자이면switch(now) {case ("("):st.push(now);break; //(를 만나면 바로 스택에 넣기case (")"):while(true) {s= st.pop();if(!(s.contentEquals("("))){result = result.concat(s);}else{st.push(s);break;}//()사이 연산자들 모조리 스택에서 빼서 추가}s = st.peek();if(s.contentEquals("("))st.pop(); break;case ("+"): case("-"): case("*"): case("/"):if(st.empty()) { //스택이 비었으면 무조건 스택에 넣기st.push(now);}else { //스택이 비지 않았으면 연산자 가중치 비교if(operator(st.peek()) >= operator(now)) //스택 내 윗것의 우선순위가 같거나 높으면{result = result.concat(st.pop());st.push(now);}else st.push(now); //스택 내 윗것의 우선순위가 작으면 now을 그냥 스택에 쌓아줌}break;default: break;}}else //숫자(double)이면result = result.concat(now); //숫자이거나 .이면 바로 result에 넣기}while(!(st.empty())){result = result.concat(st.pop());}return result;}} //바뀐 식 반환public class Test{public static void main(String[] args) {Converter con = new Converter();System.out.println("3*(4+50%)");System.out.println(con.converter("3*(4+50%)"));}}