2018년 12월 27일 목요일

[Android] 이미지 위치 바꾸기 이벤트(ImageView, ScrollView)






Button x2(Up, Down)
ImageView x2
ScrollView x2

구현하려하는 것은 이미지뷰를 위아래로 배치한 후
버튼을 눌렀을 때 이미지의 위치를 변경

ImageView imageView;
ImageView imageView2;
BitmapDrawable bitmap;

이미지뷰 아이디로 이벤트를 실행 시킬 것이기 때문에
이미지뷰 객체를 2개 생성.

imageView =  findViewById(R.id.imageView);
imageView2 =  findViewById(R.id.imageView2);

이미지뷰의 아이디로 뷰를 찾음

public void onButton1Clicked(View v){
    upImage();}
public void onButton2Clicked(View v){
    downImage();}

버튼 클릭 이벤트가 발생했을 때 
upImage와 downImage 메소드가 실행 된다.

private void upImage(){
    Resources res = getResources();    
bitmap = (BitmapDrawable)res.getDrawable(R.drawable.youtube);   
 int bitmapWidth = bitmap.getIntrinsicWidth();   
 int bitmapHeight = bitmap.getIntrinsicHeight();   
 imageView2.setImageDrawable(null);   
 imageView.setImageDrawable(bitmap);   
 imageView.getLayoutParams().width = bitmapWidth;   
 imageView.getLayoutParams().height = bitmapHeight;}

이미지를 위로 올리는 메소드는 아래의 이미지뷰를 먼저 비워주고
위의 이미지뷰에 다시 그림을 그려주는 방식을 사용한다.
아래로 내리는 방식도 동일하다.

private void downImage(){
    Resources res = getResources();    

    bitmap = (BitmapDrawable)res.getDrawable(R.drawable.youtube);
    imageView.setImageDrawable(null);               imageView2.setImageDrawable(bitmap);
}

간단한 방법으로 이미지의 위치를 바꾸는 것을 구현했다.


교재 : 안드로이드 웹프로그래밍


[Android] 이미지뷰 사용하기 (ImageView, ImageChange)

이미지를 바꾸는 메소드

private void changeImage(){
    Resources res = getResources();  
  
    bitmap = (BitmapDrawable)res.getDrawable(R.drawable.wow2); //다른 이미지 소스로 변경

    int bitmapWidth = bitmap.getIntrinsicWidth();             //이미지의 가로사이즈

    int bitmapHeight = bitmap.getIntrinsicHeight();           //이미지의 세로사이즈

    imageView.setImageDrawable(bitmap);                       //이미지뷰에 이미지를 그려준다.

    imageView.getLayoutParams().width = bitmapWidth;

    imageView.getLayoutParams().height = bitmapHeight;}



안드로이드 (Java)

안드로이드에서 이미지를 사용하는 다른 방법도 있다고 한다.

안드로이드 기본을 공부하는 과정이기 때문에 bitmap을 사용했다.



2018년 12월 25일 화요일

[JSP Board] Database create table - tableBoard

CREATE TABLE `tblBoard` (
`num`               int(11)              NOT NULL  auto_increment  ,
`name`              varchar(20)                    ,
`subject`           varchar(50)                    ,
`content`           text                           ,
`pos`                smallint(7) unsigned           ,
`ref`                 smallint(7)                    ,
`depth`             smallint(7) unsigned           ,
`regdate`          date                           ,
`pass`              varchar(15)                    ,
`ip`                  varchar(15)                    ,
`count`             smallint(7) unsigned           ,
`filename`         varchar(30)                    ,
`filesize`           int(11)                        ,
PRIMARY KEY ( `num` )
)COLLATE='euckr_korean_ci';


num - 게시글 번호 article number
name - 작성자 - writer
subject - 제목 - title
content - 내용
pos -
ref -
depth - 답글 기능 구현을 위한 뎁스
regDate - 등록 날짜 
pass - 글 비밀번호
ip - 작성자 ip
count - 조회수 - views
filename - 첨부파일 제목
filesize - 첨부파일 크기
기본키 - 게시글번호 (자동증가)

2017년 11월 5일 일요일

[C언어] 백준 1152번


문제를 보고 쉬울거라고 생각했는데 정답률이 20%인걸 보고...
왜 못 맞추는걸까...라고 생각을 했지만
처음에는 띄어쓰기만 세면 되는거아냐 ? 라고 바보같은 생각을함..
그러면 띄어쓰기만 입력했을 때 띄어쓰기 횟수만큼 숫자가 출력되니
단어의 개수와는 맞지 않고...

다시 생각해보니 라이브러리 함수중에 strtok()함수를 이용해서 토큰 추출해서
횟수를 세면 될 것 같다는 생각이 들었다 !

그래서 생각한 소스 ~































strtok() 함수에 대한 자세한 내용은 포스팅하지 않겠음!
검색하면 다~ 나오는 함수이므로 ^_^

problem reference : https://www.acmicpc.net/problem/2577

2017년 9월 26일 화요일

[C programming] ACM Hotel (Beakjoon No.10250)

[Problem]

Jiwoo, the manager of the ACM Hotel, is about to assign the vacant rooms to the guests upon their arrival. According to customers’ survey, the customers prefer the rooms which are close to the main entrance on-walk. Jiwoo likes to assign the rooms on this policy. Write a program to help Jiwoo on assigning the rooms for the guests.
For simplicity, let’s assume that the ACM hotel is a rectangular shape, an H story building with W rooms on each floor (1 ≤ H, W ≤ 99)  and that the only one elevator is on the leftmost side (see Figure 1). Let’s call this kind of hotel as H × W shaped. The main entrance is located on the first floor near the elevator. You may ignore the distance between the gate and the elevator. Also assume that the distances between neighboring rooms are all the same, the unit distance, and that all the rooms only in the front side of the hotel.

The rooms are numbered in YXX or YYXX style where Y or YY denotes the number of the floor and XX, the index of the room counted from the left. Therefore the room shaded in Figure 1 should be 305.
The customers do not concern the distance moved in the elevator though the room on the lower floor is preferred than that on the higher floor if the walking distance is same. For instance, the room 301 is preferred than the room 102 since the customer should walk for two units for the latter but one unit, for the former. Additionally, the room 2101 is preferred than the room 102.
Your program should compute the room number which should be assigned for the N-th guest according to this policy assuming that all the rooms are vacant initially. The first guest should be assigned to 101, the second guest to 201, and so on. In Figure 1, for example, the 10th guest should be assigned to the room 402 since H = 6.

[input]

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case consists of a single line containing and integers H, W, and N: the number of floors, the number of rooms on each floor, and the index of the arrival time of the guest to be assigned a room, respectively, where 1 ≤ H, W ≤ 99 and 1 ≤ N ≤ H × W.

[output]

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case consists of a single line containing and integers H, W, and N: the number of floors, the number of rooms on each floor, and the index of the arrival time of the guest to be assigned a room, respectively, where 1 ≤ H, W ≤ 99 and 1 ≤ N ≤ H × W.


[solution]

#include <stdio.h>

int main(){

int tc;                    //variable definition :  test_case
scanf("%d",&tc); 
while(tc>0){
int h,w,n;       // h = height, w = width, n = the number of customers
scanf("%d %d %d",&h,&w,&n);
int room[h][w];  // array size = height * width ( the number of rooms)

int i,j;



for(i=1;i<=w;i++){  
for(j=1;j<=h;j++){  
room[j-1][i-1]=(100*j)+i;      // ex) A room number = height * 100 + width  ----> No.301 = 3 * 100 + 1   ** Insert a room number in turns into the array

}   
if(n%h==0) printf("%d\n",room[h-1][n/h-1]);   
          else printf("%d\n",room[(n%h)-1][n/h]);
// If the number of customers and height are same, (height 6, customers 6) or
if the number of customers is multiple of height, customers will be enter in the top room.
The room number is one less than the index. --> room[h-1][n/h-1]
                             Except in the case of above, the row has the height of hotel. the column has room nuber. 
                             In other words, you can make this expression.  room[(n%h)-1][n/h]

tc--;
}

return 0;
}
problem reference : https://www.acmicpc.net/problem/10250


Thank you for reading. 
I never stop programming. Because I'm a beginner. :)

2017년 9월 25일 월요일

[C언어] 백준 2577번




















세개의 자연수 A,B,C가 주어질 때 A*B*C를 계산한 결과에 0부터 9까지 각각의 숫자가 몇 번씩 쓰였는지를 구하는 프로그램을 작성한다.

A,B와 C는 100보다 같거나 크고, 1,000보다는 작은 자연수이다
100 <= A,B,C<1000

나온 결과를 10으로 나누었을 때 나머지가 결국 해당 자리 숫자가 된다.
그러므로 우선 해당 숫자가 몇번 나왔는지 확인할 배열을 선언해준다.(크기는 10)
반복문은 결과 값이 0이 될 때까지 10으로 나누어준다.
그리고 반복문 안에 switch case문을 넣어서 해당 숫자가
나올 때마다 해당 배열에 1씩 증가 시켜준다.
ex) 1180을 10으로 나눈 값은 118이고 나머지는 0
그러면 0에 해당하는 배열[0]의 값을 1증가 시켜준다.
그렇게 해서 최종적으로 0보다 작아졌을 때 while문을 탈출하게 되고
배열에는 숫자의 개수 만큼 저장되어 있다.
마지막으로, 배열을 출력해준다.

C언어를 시작한지 3주정도 됐는데 어렵다.. 쉽지 않은 언어이고
이전에 자바를 조금 했고, 비주얼 베이직을 조금 배웠던 나는
나름 이해가 빠르다고 생각했는데 전혀[!] 아니라는 것을
깨달았고 더욱더 많은 공부가 필요하다는 것을 느낀다.
나와 같으신 분이 많을테니까 그분들과 내자신에게 격려의 박수를 보낸다.
문제 해결 시간 50분이상 소요...


#include <stdio.h>

int main(){
int a,b,c,cnt[10]={0,}; //입력받을 수 3개 a,b,c를 변수 선언.
int result=0; //결과 값을 저장할 변수 선언
scanf("%d %d %d", &a, &b, &c);
result = a*b*c;       //result에 결과 값 대입
while(result>0){
switch(result%10){
case 0 :
cnt[0]++;
break;
case 1 :
cnt[1]++;
break;
case 2 :
cnt[2]++;
break;
case 3 :
cnt[3]++;
break;
case 4 :
cnt[4]++;
break;
case 5 :
cnt[5]++;
break;
case 6 :
cnt[6]++;
break;
case 7 :
cnt[7]++;
break;
case 8 :
cnt[8]++;
break;
case 9 :
cnt[9]++;
break;
}
result /= 10;
}
int i = 0;
while(i<10){
printf("%d\n",cnt[i]);
i++;
}
return 0;
}

problem reference : https://www.acmicpc.net/problem/2577

2017년 9월 15일 금요일

파일 구조 1장 연습문제 풀이.

1.1 데이터 레코드들을 메인 메모리에 저장하지 않고 보조 저장 장치에 파일로 구성하는 이유를 설명해 보라.
: 메인 메모리에 전부 적재하기에 데이터 양이 너무 많다. (파일로 나누어 디스크에 저장하면 관리하기에 편함), 프로그램은 특정시간에 데이터 집합의 일부만 접근하기 때문에 데이터 전부를 메인 메모리에 저장시킬 필요가 없다. 데이터를 특정 프로그램과 별도로 보관시켜 데이터의 독립성을 유지하여 여러 프로그램이 응용 가능하게 한다.

1.2 대부분의 컴퓨터 시스템에서는 여러 가지 파일 조직 방법을 제공하고 있다. 그 이유는 무엇인가를 구체적으로 설명해 보라.
: 파일 조직 방법에 따라 컴퓨터 시스템이 디스크의 데이터를 기다리는데 시간을 허비하지 않고 효율적으로 데이터를 처리할 수 있게 된다. 굉장히 다양한 타입의 데이터와 응용의 다양성이 파일 구조 설계를 어렵게 만든다. 왜냐하면 한 경우에 최적인 것이 또 다른 경우에는 아주 형편없는 것이 될 수 있기 때문이다.  

1.3 파일을 사용되는 기능에 따라 분류해 보고, 간단히 설명해 보라.
1. 마스터 파일: 어느 한 시점에서 조직체의 업무들에 관한 정적인 면을 나타내는 데이터의 집합현재성을 정확히 유지함으로써 현실세계에 대한 정확한 정보제공,보통 파일이라 하면 Master file을 의미한다.
2. 트랜잭션 파일: 마스터 파일에 적용할 트랜잭션을 모아 저장한 파일,트랜잭션은 새로운 레코드 삽입, 현존 레코드 삭제,수정
3. 보고서 파일: 사용자에게 데이터 검색의 결과를 보여주기 위해 데이터를 일정한 형식으로 정리 해서 저장해 놓은 파일. (Hardcopy 보고서 출력, 단말 장치 화면에 display
4. 작업 파일: 어느 한 프로그램에서 생성된 출력 데이터를 다른 프로그램의 입력 데이터로 사용하기 위해 만드는 임시 파일. 최종 목표를 달성하는 과정에서 만들어지는 중간결과를 저장하는 파일.
5. 프로그램 파일: 메인 메모리나 보조 저장 장치에 저장되어 있는 데이터를 처리하기 위한명령어들(프로그램)을 저장하고 있는 파일.
6. 텍스트 파일: 문자 숫자와 그래픽 data를 포함하고 있는 파일로서 텍스트 편집기의 입력과 출력으로 사용.

1.4 파일에 대해 수행할 수 있는 일반적인 연산을 열거하고 설명해 보라.
1. 파일 생성: 데이터 골격의 설계(data definition: 데이터 정의), 데이터 수집과 확인.
2. 파일 기록: 마스터 파일 내용을 기록 또는 출력(output)
3. 파일 판독: 마스터 파일 내용을 판독 또는 입력.
4. 파일 삭제: 디렉토리로부터 파일 위치 검색, 할당된 디스크 공간 변화, 디렉토리 엔트리 삭제.
5. 파일 개방과 폐쇄: (개방)연산을 수행할 수 있도록 파일 준비, 파일 개방 후 판독과 기록 가능. 메인메모리에 파일 전송을 위한 버퍼 할당. (폐쇄)파일 사용 종료. 버퍼의 출력 데이터를 디스크에 기록. 할당된 버퍼의 반환.

1.5 어떤 기관의 특정 업무를 선정하여 그 업무를 전산화하기 위한 시스템 흐름도를 작성하라. 마스터 파일, 트랜잭션 파일, 보고서 파일, 작업 파일, 프로그램 파일을 각각 명시하고, 그 밖에 다른 형태의 파일을 추가할 수 있으면 명시해 보라.
* 00회사의 인사 업무 전산화 시스템.
마스터 파일: 인사 마스터 파일(현재의 HR을 반영하는 파일)
트랜잭션 파일: 인사 변동의 내용을 담은 데이터 파일
보고서 파일: 00부서의 인사 정보, 최근 인사 정보에 대한 데이터들을 정리해 놓은 파일
작업 파일: 인사 정보 변경을 위한 작업 파일.
프로그램 파일: 작업 파일의 작업을 수행하기 위한 명령어들을 담은 프로그램.

1.6 파일 구조 방법을 선택할 때 고려해야 될 요소에는 어떤 것이 있는지 알아보고 설명하라.
1. 가변성: 파일의 전체 레코드 수에 대해 추가되거나 삭제되는 레코드의 수를 말한다. 가변성이 높은 동적 파일은 빠른 접근과 갱신이 필요하다.
2. 활동성: 주어진 기간 동안에 파일의 총 레코드 수에 대해 접근한 레코드 수의 비율. 활동성이 높으면 순차 파일 구조가 유리.
3. 사용 빈도수: 일정기간 동안의 파일 사용 빈도수. 가변성과 활동성에 밀접히 관련. 빈도수가 낮을 경우 순차 파일 구조가 유리하며 높을 경우에는 임의 접근 구조가 유리하다.
4. 응답 시간: 검색이나 갱신에 대해 요구하는 응답 시간. 빠른 응답시간 조건에는 임의 접근 방법을 선택하며, 순차적으로 정렬된 키를 이용한 검색에는 순차 접근방법 가능.
5. 파일 크기: 레코드 수와 각 레코드 길이가 파일 크기를 결정한다. 파일 성장을 유연하게 수용할 수 있는 구조가 필요하다.
6. 파일 접근 유형: 파일 연산의 유형과 접근 형식에 따라 파일 구조를 결정.

1.7 일괄 처리와 대화식 처리에 각각 적절한 파일 조직 방법의 특징을 설명해 보라.
일괄 처리: 마스터 파일을 효율적으로 접근할 수 있도록 트랜잭션들을 그룹으로 구성한다. 트랜잭션 그룹을 처리하는 성능이 주요 관심사.

대화식 처리: 트랜잭션이 터미널에 도착하는 대로 처리되기 때문에 트랜잭션은 도착 순서대로 구성된다. 개개 트랜잭션의 처리 성능이 주요 관심사.

[Android] 이미지 위치 바꾸기 이벤트(ImageView, ScrollView)

Button x2(Up, Down) ImageView x2 ScrollView x2 구현하려하는 것은 이미지뷰를 위아래로 배치한 후 버튼을 눌렀을 때 이미지의 위치를 변경 ImageView imageView ; ...