C, JAVA, python 오답노트
조회: 233
댓글: 0개
2023.09.24 0:19 일요일
- c언어
- switch case에서 break; 없으면 내 밑으로 다 실행한다. default까지
- printf는 python의 print처럼 자동 개행 없다.
#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 }
#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 }
- int ary[] = {4,5,6}에서 *ary는 4고 *(ary+1)은 5다
#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); }
#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); }
- c언어의 나머지 연산자는 //가 아니라 %다
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",(가)); } } //배열 인덱스로 사칙연산을 넣는 센스
#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을 가르키잖아.. 문제 똑바로 봐라.."
- n/4는 n%4==0 cnt++ 와 동일하다
- int main 말고 전역 변수 먼저 확인해라
- JAVA
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
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
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 되는거다..
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)); } }
메소드 오버라이딩, 재귀함수는 피라미드
- System.out.print("1") ... = 123
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 선언 안 하고 같이 딸려 올려보내
- ^ : xor 게이트는 서로 다를 때 1이다
- =인지 += 인지 문제 잘 보라고~~
- 56+5가 어케 71이 되냐.. 정신 차리라고~~
- > 인지 < 인지 잘 봐라 정신차리라고~~
- 6이랑 12는 뭐냐, 3의 배수라고 다 홀수가 아니다 정신 차리라고~~
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); } }
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부터
변수 가져오는 것도 가까운 것부터.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
- python
a={'한국','중국','일본'} a.add('베트남') a.add('중국') a.remove('일본') a.update(['한국','홍콩','태국']) print(a) #이미 있는 녀석을 add하면 그대로 #update했을 때 이미 있는건 그대로, 없는것만 추가
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 중간에 개행 있잖아 종원아..
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]이 있으니까 첫글자만 따오잖아 종원아..
a = 100 result = 0 for i in range(1,3): result = a >> i result = result + 1 print(result) #for 돌 때마다 result 초기화되잖아 종원아..
a,b = 100, 200 print(a==b) #그냥 평범한 숫자 비교야 종원아..
def exam(num1, num2=2): print('a=', num1, 'b=', num2) exam(20) #, 붙으면 띄어쓰기
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 랑 비슷함
TestList = [1,2,3,4,5] TestList = list(map(lambda num : num + 100, TestList))) print(TestList) #람다 잘 알았지?