UVa 1585 Score【数组处理】

来源:互联网 发布:如何申请淘宝网店步骤 编辑:程序博客网 时间:2024/06/01 10:06

题目链接:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=830&page=show_problem&problem=4460


字符串处理,注意循环的跳出判断,还是提前测出数组长度,控制长度比较保险.............

#include<stdio.h>#include<string.h>char x[105];void slove(){int len=strlen(x),cnt=0;for(int i=0;i<len;++i){int tp=0;while(i<len&&x[i]!='X'){cnt+=++tp;++i;}}printf("%d\n",cnt);}int main(){int t;//freopen("shuju.txt","r",stdin);scanf("%d",&t);while(t--){scanf("%s",x);slove();}return 0;}


0 0
原创粉丝点击