pC.NET

Welcome to oscc.kr



 문자열 좌우회전 이동
2020-05-12 10:43:16
Hit : 1274

작성자 : 피시키드
- File #1 : 47.c(912 Byte), Download : 22

입력받은 문자열을 원하는 방향, 횟수만큼 회전시켜준다.

 

'ABC'를 받으면 'ABCABCABC'의 문자열을 만든다.

그리고 가운데 문자열을 기준으로 +-이동하여 출력시켜준다.

  

직접 요소를 치환해가면서 이동하려면 머리아프다.

 

 

#include <stdio.h> // 문자열 이동시키기 // LANG,r,1 -> GLAN int strleng(char *str) { int cnt = 0;while (str[cnt] != '\0') cnt = cnt + 1; return cnt; } int main() { int i; int j; char str[50]; char d; int cnt; int leng; char str2[150]; printf("input string: "); scanf("%s", str); scanf("%c", &d); // stdin에 남아있는 개행문자 비우기 printf("input direction(L/R): "); scanf("%c", &d); printf("input move count: "); scanf("%d", &cnt); leng = strleng(str); for (i=0;i<=2;i++) { for (j=0;j<=leng;j++) str2[i*leng+j] = str[j]; } str2[i*j+1] = '\0'; if (cnt >= leng) cnt = cnt % leng; if (( d == 'r') || ( d == 'R')) cnt = - cnt; for(i=leng+cnt;i <= leng*2 -1 + cnt;i++) { printf("%c",str2[i]); } return 0; }

 

* 피시키드님에 의해서 게시물 이동되었습니다 (2024-04-26 18:49)

  피시키드
회원님의 소개글이 없습니다.
 6490
 83


구조체 선언
10진수 2진수로 변환하여 출력하기

Copyright (C) 1997-2025 All Rights Reserved.

Powered by
DNS server, DNS service 우분투 리눅스 웹서비스 AbuseIPDB Contributor Badge