#include using namespace std; int main() { char ci[50]; cin.getline(ci,50); char p1[25]; int i=0,j=0; while(ci[i]!='\0') { p1[j]=ci[i]; i=i+2; j=j+1; } p1[j]='\0'; cout<<p1<<endl; return 0; }
2条回答 默认 最新
- CSDN专家-深度学习进阶 2021-07-01 21:11关注
改成这样就好了,之前i+2会正好跳过结束符,导致循环错误
#include <bits/stdc++.h> using namespace std; int main() { char ci[50]; cin>>ci; char p1[25]; int i=0,j=0; while(i<strlen(ci)) { p1[j]=ci[i]; i=i+2; j=j+1; } p1[j]='\0'; cout<<p1<<endl; return 0; } //Coheifnia
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报