3421 - 考试九 字符串分割
将一个字符串(长度不超过100)用";"分割成不同的字符串并输出。
Input
输入一个字符串之前用";"分隔;
Output
按行输出分割后的字串;
Examples
Input
hello;world;
Output
hello world
Solution C
int main(int argc, const char * argv[]) { char data[100]; char tmp [100]; int i = 0; int j = 0; int count = 0; char c = data[i]; gets(data); while (c != '\0') { while(c != ';') { i++; count ++; c = data[i]; } memcpy(tmp,&data[j],sizeof(char)*count); count = 0; printf("%s\n",tmp); i++; j = i; c = data[i]; } }
Solution C++
#include<bits/stdc++.h> using namespace std; string a; int main() { cin>>a; for(int i=0;i<a.size();i++) { if(a[i]!=';') cout<<a[i]; else cout<<endl; } return 0; }