정보처리기사

C, JAVA, python 오답노트

조회: 233 댓글: 0개 2023.09.24 0:19 일요일
  1. c언어
    1. switch case에서 break; 없으면 내 밑으로 다 실행한다. default까지
    2. printf는 python의 print처럼 자동 개행 없다.
    3.  

      #include <stdio.h>   main(){     char *p="KOREA";     printf("%s\n",p);//KOREA     printf("%s\n",p+3);//EA     printf("%c\n",*p);//K     printf("%c\n",*(p+3));//E     printf("%c\n",*p+2);//M }
    4. #include <stdio.h> void main(){     struct insa {         char name[10];         int age;     }     a[] = {"Kim",28,"Lee",38,"Park",42,"Choi",31};     struct insa *p;     p = a;     p+=2;     printf("%s\n", p-> name);//Park     printf("%d\n", p-> age);//42 }
    5. int ary[] = {4,5,6}에서 *ary는 4고 *(ary+1)은 5다
    6. #include <stdio.h>  int main(){     int *arr[3];     int a = 12, b = 24, c = 36;     arr[0] = &a;     arr[1] = &b;     arr[2] = &c;          printf("%d\n", *arr[1]);//24     printf("%d\n", *arr);//-1823123     printf("%d\n", **arr);//12     printf("%d\n", *arr[1] + **arr + 1); }
    7. #include <stdio.h>  struct jsu {     char name[12];     int os, db, hab, hhab; }; int main(){     struct jsu st[3] =     {{"데이터1", 95, 88},      {"데이터2", 84, 91},      {"데이터3", 86, 75}};     struct jsu* p;          p = &st[0];     (p+1)->hab = (p+1)->os + (p+2)->db;     //여기서 p+1hab 정의했구만 뭘 없어 ㅅㅂ     (p+1)->hhab = (p+1)->hab + p->os + p->db;          printf("%d\n", (p+1)->hab + (p+1)->hhab); }
    8. c언어의 나머지 연산자는 //가 아니라 %다
    9. int main(){     int n[5];     int i;          for(i=0;i<5;i++){         printf("숫자를 입력하세요 : ");         scanf("%d",&n[i]);     }          for(i=0;i<5;i++){         printf("%d",(가));     } } //배열 인덱스로 사칙연산을 넣는 센스
    10. #include<stdio.h>  #include<stdlib.h>    char n[30];   char *test(){     printf("입력하세요 : ");     gets(n);     return n; }   int main(){     char * test1;     char * test2;     char * test3;       test1 = test();     test2 = test();     test3 = test();       printf("%s\n",test1);     printf("%s\n",test2);     printf("%s",test3); } //세 포인터 변수들이 "전역변수 n을 가르키잖아.. 문제 똑바로 봐라.."
    11. n/4는 n%4==0 cnt++ 와 동일하다
    12. int main 말고 전역 변수 먼저 확인해라
  2. JAVA
    1. class Parent{   void show(){System.out.println("parent");}   } class Child extends Parent{   void show() {System.out.println("child");} }   class Main {     public static void main(String args[]) {      Parent pa=(가) Child();     pa.show();   }  }

      (가) = new

    2. abstract class Vehicle{ 	String name;     abstract public String getName(String val);     public String getName(){     	return "Vehicle name:" + name;     } }   class Car extends Vehicle{   private String name; 	public Car(String val){     	name=super.name=val;    } public String getName(String val){ 	return "Car name : " + val;    } public String getName(byte val[]){ 	return "Car name : " + val;    } }   public class Main { 	public static void main(String[] args){     Vehicle obj = new Car("Spark");     System.out.print(obj.getName());     } }

      Vehicle name : Spark

    3. public class Main { 	public static void main(String[] args){     int i=0, sum=0;     while (i<10){     	i++;         if(i%2 ==1)         	continue;         sum += i;      }      System.out.println(sum);    } }

      i++ 후치연산자 잘 봐라.. 9로 들어왔어도 10 되는거다..

    4. class Parent{ 	public int compute(int num){     	if(num <=1) return num;         return compute(num-1) + compute(num-2);     }  }    class Child extends parent {  	public int compute(int num){     	if(num<=1) return num;         	return compute(num-1) + compute(num-3);         }    }       class Main{   	public static void main (String[] args){     Parent obj = new Child();     System.out.print(obj.compute(4));    }  }

      메소드 오버라이딩, 재귀함수는 피라미드

    5. System.out.print("1") ... = 123
    6. public class Main {    public static void main(String[] args){       System.out.print(Main.check(1));    }       (가) String check (int num) {       return (num >= 0) ? "positive" : "negative";    } }

      (가) = static 선언 안 하고 같이 딸려 올려보내

    7. ^ : xor 게이트는 서로 다를 때 1이다
    8. =인지 += 인지 문제 잘 보라고~~
    9. 56+5가 어케 71이 되냐.. 정신 차리라고~~
    10. > 인지 < 인지 잘 봐라 정신차리라고~~
    11. 6이랑 12는 뭐냐, 3의 배수라고 다 홀수가 아니다 정신 차리라고~~
    12. class Static{   public int a=20;   static int b=0; }     public class Main {   public static void main(String[] args) {     int a=10;     Static.b=a;     Static st=new Static();       System.out.println(Static.b++);      System.out.println(st.b);//10인줄 알았는데 11이다      System.out.println(a);      System.out.println(st.a);   } }
    13. class Parent {   int x = 100;     Parent() {     this(500);   }   Parent(int x) {     this.x = x;   }   int getX() {     return x;   } } class Child extends Parent {   int x = 1000;   Child() {     this(5000);   }   Child(int x) {     this.x = x;   } }   public class Main {   public static void main(String[] args) {     Child obj = new Child();     System.out.println(obj.getX());   } }

      생성자 호출은 유교상이라서 Parent부터
      변수 가져오는 것도 가까운 것부터.

    14. public class Main {   public static void main(String[] args) { 	  String str1 = "Programming";      String str2 = "Programming";     String str3 = new String("Programming");            System.out.println(str1==str2);     System.out.println(str1==str3);     System.out.println(str1.equals(str3));     System.out.print(str2.equals(str3));   } }

      t,f,t,t

  3. python
    1. a={'한국','중국','일본'} a.add('베트남') a.add('중국') a.remove('일본') a.update(['한국','홍콩','태국']) print(a)  #이미 있는 녀석을 add하면 그대로 #update했을 때 이미 있는건 그대로, 없는것만 추가
    2. lol = [[1,2,3],[4,5],[6,7,8,9]] print(lol[0]) print(lol[2][1]) for sub in lol:   for item in sub:     print(item, end = '')   print()  #lol[2][1]이 어케 6이니 종원아... #for 중간에 개행 있잖아 종원아..
    3. class good : 	li = ["seoul", "kyeonggi","inchon","daejeon","daegu","pusan"]   g = good() str01 = '' for i in g.li: 	str01 = str01 + i[0]      print(str01)  #i[0]이 있으니까 첫글자만 따오잖아 종원아..
    4. a = 100 result = 0 for i in range(1,3):    result = a >> i    result = result + 1 print(result)  #for 돌 때마다 result 초기화되잖아 종원아..
    5. a,b = 100, 200  print(a==b) #그냥 평범한 숫자 비교야 종원아..
    6. def exam(num1, num2=2):   print('a=', num1, 'b=', num2) exam(20) #, 붙으면 띄어쓰기
    7. a="REMEMBER NOVEMBER" b=a[:3]+a[12:16] c="R AND %s" % "STR"; print(b+c)  # 시작:끝:간격 # 시작은 0,1,2 # 끝은 썡 개수 # %f 실수 %d 정수 %d 문자열 c언어 printf 랑 비슷함
    8. TestList = [1,2,3,4,5] TestList = list(map(lambda num : num + 100, TestList)))   print(TestList)  #람다 잘 알았지?
captcha