輸入一個字符串和一個整數 k ,截取字符串的前k個字符并輸出。
數據范圍:字符串長度滿足 1≤n≤1000, 1≤k≤n
輸入描述:
1.輸入待截取的字符串
2.輸入一個正整數k,代表截取的長度
輸出描述:截取后的字符串
輸入:
abABCcDEF
6
輸出:abABCc
輸入:
bdxPKBhih
6
輸出:bdxPKB
#include <stdio.h>
int main(){char str[101];while(scanf("%s", str) > 0) {int n;scanf("%d", &n);str[n] = '\0';printf("%s\n", str);}
}