字符串分隔,C满分答案
字符串分隔
http://www.nowcoder.com/questionTerminal/d9162298cb5a437aad722fccccaae8a7
#include <stdio.h> #include <stdlib.h> #define str_lenth 100 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int func_lenth(char* str,int lenth) //测量字符串长度函数 { int i; for(i=0;i<lenth;i++) { if(str[i]=='\0') { lenth=i; break; } } return lenth; } int main() { char a[str_lenth]={0}; char b[str_lenth]={0}; int i,j; int head=1,rear=0; int l_a,l_b; scanf("%s",a); scanf("%s",b); l_a=func_lenth(a,str_lenth); l_b=func_lenth(b,str_lenth); for(i=0;i<l_a;i++) //满8的字符输出,不满的输出前面字符 { if((i+1)%8==0)printf("%c\n",a[i]); else printf("%c",a[i]); } if(i%8!=0) //不满8的字符后补上字符0 { while((i+1)%8) { printf("%c",'0'); i++; } printf("%c\n",'0'); } for(i=0;i<l_b;i++) //处理第二个字符串 { if((i+1)%8==0)printf("%c\n",b[i]); else printf("%c",b[i]); } if(i%8!=0) { while((i+1)%8) { printf("%c",'0'); i++; } printf("%c\n",'0'); } //while(1); }