hdoj 1004 Let the balloon rise (字符串处理问题)
来源:互联网 发布:炫酷网站引导页源码 编辑:程序博客网 时间:2024/05/22 13:53
思路:每输入一个字符串,跟前面的进行比较,如果有一样的前面的气球数量+1,如果没有气球种类加1
代码如下:
#include <stdio.h>#include <stdlib.h>#include <string.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */struct balloon//定义气球的结构体,存储每种气球的颜色和数量 {char cl[20];int count;};int judge(char *p1,char *p2)//判断两个字符串是否相等;如果是指针的新手千万记得p1,p2指向的只是字符数组的首地址 {while(*p1==*p2 && *p1){p1++;p2++;} if(!*p1 && !*p2)return 1;elsereturn 0;}int main(int argc, char *argv[]) {int x;int n;int i;int key;int m;int max;char b[20];char maxball[20];struct balloon ball[1200];while(scanf("%d",&n) && n!=0){m=0;max=0;for(i=0;i<1200;i++)//一定要进行初始化,防止影响下一次的测试 {memset(ball[i].cl,'\0',sizeof(char)*20);ball[i].count=0;}for(i=0;i<n;i++)//每输入一次判断一次,如果是有过的气球则数量加1,没有的颜色种类加1 {scanf("%s",b);key=0;for(x=0;x<m;x++){if(judge(ball[x].cl,b)==1){ball[x].count++;key=1;}}if(key==0){strcpy(ball[m].cl,b);m++;}} max=ball[0].count;//找出数量最多的气球 strcpy(maxball,ball[0].cl);for(i=1;i<n;i++){if(ball[i].count>max){max=ball[i].count;strcpy(maxball,ball[i].cl);}}printf("%s\n",maxball);}return 0;}
阅读全文
0 0
- hdoj 1004 Let the balloon rise (字符串处理问题)
- hdoj 1004 Let the Balloon Rise(字符串比较问题)
- [字符串][第二阶段-字符串处理][HDOJ-1004]Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise(字符串)
- HDOJ - 1004 - Let the Balloon Rise(字符串)
- hdu 1004 Let the Balloon Rise ( 字符串简单处理)
- Num 12: HDOJ: 题目1004 : Let the Balloon Rise( 字符串问题 )
- HDOJ 1004 Let the Balloon Rise (map)
- HDOJ-1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- hdoj 1004 Let the Balloon Rise
- hdoj.1004 Let the Balloon Rise 20140726
- HDOJ Let the Balloon Rise 1004
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise(水题)
- 【HDOJ】【1004】Let the Balloon Rise
- android 截屏 h264封装flv注意事项
- Hive编程(七)【HiveQL:视图】
- 第27篇.华为服务器安装
- sql 基本语句
- 数据库面试
- hdoj 1004 Let the balloon rise (字符串处理问题)
- h5破解网站图片防盗链
- AMOS分析技术:独立模型、饱和模型和假设模型
- Ubuntu修改环境变量
- Kotlin的变长参数
- 长按二维码不识别
- VC++6.0(带破解版助手)下载、安装 教程
- python之for、while、if练习题
- Unable to execute dex: Multiple dex files define 解决方法