레이블이 [C] Baekjoon인 게시물을 표시합니다. 모든 게시물 표시
레이블이 [C] Baekjoon인 게시물을 표시합니다. 모든 게시물 표시

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

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

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