/*
#include <stdio.h>
int main()
{
char str[51] = {};
gets(str);
int h = 0;
int db = 0;
for(int i = 0; str[i] != NULL; i++)
{
if(i != 0)
{
if(str[i-1] == str[i])
{
h += 5;
}
else{
h += 10;
}
}
else{
h += 10;
}
}
printf("%d", h);
}
#include <stdio.h>
int main()
{
int year, a = 7, b = 9;
scanf("%d", &year);
for(int i = 1; i <= year; i++)
{
if(a == 10){
a = 0;
}
if(b == 12){
b = 0;
}
a++;
b++;
}
printf("%c%d", b + 'A'- 1, a - 1);
}
#include <stdio.h>
int main()
{
char str[21] = {};
gets(str);
for(int i = 0; str[i] != NULL; i++)
{
printf("\'%c\'\n", str[i]);
}
}
포인터 주소를 저장하는 변수
*/
/*
#include <stdio.h>
void f(int* pa)
{
printf("in f : %d\n",*pa);
*pa=50;
}
int main()
{
int a=10;
printf("before : %d\n",a);
//f(a); // call by value
f(&a);
printf("after : %d\n",a);
return 0;
}
#include <stdio.h>
void f(char* str)
{
*(str+1)=0;
//str[1]=0;
//printf("in f : %s\n",str);
//str[0]='j';
}
int main()
{
char str[50]="hello";
//str == &str[0]
//printf("%d",&str[0]);
f(str);
printf("%s",str);
}
#include <stdio.h>
int x, y;
void myswap(int* pa, int* pb)
{
x = *pa;
y = *pb;
if(x > y){
*pa = y;
*pb = x;
}
}
main()
{
int a, b;
scanf("%d%d", &a, &b);
myswap(&a, &b);
printf("%d %d", a, b);
}
#include <stdio.h>
char* mysubstr(char* str, int start, int count)
{
str[start + count] = 0;
return &str[start];
}
int main()
{
char str[101] = {};
gets(str);
int s, c;
scanf("%d %d", &s, &c);
printf("%s",mysubstr(str, s, c));
}
c언어 문법 (끝)
* c언어 자료구조 data structure
1. stack 2. queue 3. tree 4.Sort 5.Search 6.Graph(DFS/BFS)
* 새로운 다른 언어
1. Java 2.Python 3. Unity(자료구조) ... 4. 앱인벤터 5. ..
#include <stdio.h>
int main()
{
char memo[26]={};
char alpha[26] = {};
char str[101] = {};
gets(str);
for(int i = 0; str[i]!=NULL; i++)
{
memo[str[i]-'a']++;
}
for(int i = 0; i < 26; i++)
printf("%c:%d\n", 'a' + i, memo[i]);
}
#include <stdio.h>
int main()
{
char strA[101] = {}, strB[101] = {};
int a, b;
scanf("%s %s", strA, strB);
for(int i = 0; strA[i] != NULL && strB[i] != NULL; i++)
{
if(strA[i + 1] == NULL){
a = i;
}
if(strB[i + 1] == NULL){
b = i;
}
}
for(int i = 0; strA[i] != NULL && strB[i] != NULL; i++)
{
if(a != b){
if(strA[i + 1] == NULL && strB[i + 1] != NULL){
printf("%s %s", strA, strB);
break;
}
else if(strA[i + 1] != NULL && strB[i + 1] == NULL){
printf("%s %s", strB, strA);
break;
}
}
else{
if(strA[i] < strB[i]){
printf("%s %s", strA, strB);
break;
}
else if(strB[i] < strA[i]){
printf("%s %s", strB, strA);
break;
}
}
}
}
#include <stdio.h>
int main()
{
int san, sbn, scn;
char sA[21] = {},
sB[21] = {},
sC[21] = {};
scanf("%s %s %s", sA, sB, sC);
san=strlen(sA);
sbn=strlen(sB);
scn=strlen(sC);
if( sA[san - 1] == sB[0]
&&sB[sbn - 1] == sC[0]
&&sC[scn - 1] == sA[0])
printf("good");
else
printf("bad");
}
*/