日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ——字符串插入

發布時間:2023/12/19 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ——字符串插入 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
歡迎來我的個人網站:http://www.rxwcv.cn

2:字符串插入

  • 查看
  • 提交
  • 統計
  • 提問
總時間限制:?
1000ms?
內存限制:?
65536kB
描述
有兩個字符串str和substr,str的字符個數不超過10,substr的字符個數為3。(字符個數不包括字符串結尾處的'\0'。)將substr插入到str中ASCII碼最大的那個字符后面,若有多個最大則只考慮第一個。
輸入
輸入包括若干行,每一行為一組測試數據,格式為
str substr
輸出
對于每一組測試數據,輸出插入之后的字符串。
樣例輸入
abcab eee 12343 555
樣例輸出
abceeeab 12345553

1 # include<stdio.h> 2 # include<string.h> 3 4 int main(void) 5 { 6 char s1[11], s2[4]; 7 int i; 8 while(scanf("%s%s", s1, s2)!=EOF) 9 { 10 int max=0; 11 int len=strlen(s1); 12 for(i=0; i<len; i++) 13 { 14 if(s1[i]>s1[max]) 15 { 16 max=i; 17 } 18 } 19 for(i=0; i<=max; i++) 20 printf("%c", s1[i]); 21 printf("%s", s2); 22 for(i=max+1; i<len; i++) 23 printf("%c", s1[i]); 24 printf("\n"); 25 } 26 27 return 0; 28 }

?

?

1 #include <cstdio> 2 #include <cstring> 3 4 const int MAX_STRING_LEN = 15; 5 6 bool readLine(char *str, char *substr) 7 { 8 bool bEof = false; 9 10 if (2 == fscanf(stdin, "%s %s", str, substr)) 11 { 12 bEof = true; 13 } 14 15 return bEof; 16 } 17 18 void insert(char *str, char *substr) 19 { 20 int i, maxIdx; 21 size_t size = strlen(str); 22 23 // find the index of the maximum ascii code 24 maxIdx = 0; 25 for (i=1; i<size; ++i) 26 { 27 if (str[maxIdx] < str[i]) 28 { 29 maxIdx = i; 30 } 31 } 32 33 // shift right to make space 34 for (i=size; i>maxIdx; --i) 35 { 36 str[i+3] = str[i]; 37 } 38 39 // insert the substr 40 ++i; 41 str[i++] = substr[0]; 42 str[i++] = substr[1]; 43 str[i] = substr[2]; 44 } 45 46 void print(char *str) 47 { 48 printf("%s\n", str); 49 } 50 51 int main(void) 52 { 53 char str[MAX_STRING_LEN] = {'\0'}; 54 char substr[MAX_STRING_LEN] = {'\0'}; 55 56 while (readLine(str, substr)) 57 { 58 insert(str, substr); 59 print(str); 60 } 61 62 return 0; 63 }

?

歡迎來我的個人網站:http://www.rxwcv.cn

轉載于:https://www.cnblogs.com/Hewie/p/3439845.html

總結

以上是生活随笔為你收集整理的POJ——字符串插入的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。