| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6687 人关注过本帖
标题:出个小题 活跃下论坛气氛
取消只看楼主 加入收藏
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
结帖率:94.72%
收藏
已结贴  问题点数:20 回复次数:20 
出个小题 活跃下论坛气氛
【问题描述】
从文件中输入N(1≤N≤10000)个由小写英文字母组成的字符串,每个字符串的长度不超过200,统计它们出现的次数。
【输入】
第一行:N
从第二行到第N+1行,每行一个字符串。
【输出】
按输入顺序输出每个字符串及出现的次数。每行包括一个字符串和这个字符串出现的次数,它们之间用一个空格隔开

【输入样例】
10
abcde
abc
aabbc
abcde
abcde
abc
abc
abcde
aabbc
abc


【输出样例】
abcde 4
abc 4
aabbc 2

[ 本帖最后由 BlueGuy 于 2009-8-24 22:00 编辑 ]
搜索更多相关主题的帖子: 查找 
2009-08-22 19:02
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
就查 BlueGuy 是否在数组中

我就是真命天子,顺我者生,逆我者死!
2009-08-22 20:01
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
回复 3楼 zqy110007
是 strcmp

我就是真命天子,顺我者生,逆我者死!
2009-08-23 07:01
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
回复 7楼 wxjeacen
你写个输入就行了
像这样
for (i = 0; i < 1000; i++)
    gets(a[i]);

我就是真命天子,顺我者生,逆我者死!
2009-08-23 13:04
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
Perhaps the most obvious difference is that DirectX, as opposed to OpenGL, is more than just a graphics API. DirectX contains tools to deal with such components of a game as sound, music, input, networking, and multimedia. On the other hand, OpenGL is strictly a graphics API. So what aspect of OpenGL sets it apart from the DirectX graphics component?

Well, first things first: both APIs rely on the use of the traditional graphics pipeline. This is the same pipeline that has been used in computer games since the early days of computer graphics. Although it has been modified in slight ways to adapt with advancements in hardware, the basic idea remains intact.

Both OpenGL and DirectX describe vertices as a set of data consisting of coordinates in space that define the vertex location and any other vertex related data. Graphics primitives, such as points, lines, and triangles, are defined as an ordered set of vertices. There is a difference in how each API handles how vertices are combined to form primitives.

There are a bunch of differences in the DirectX and OpenGL APIs, so I will list a few of those for you. This chart is based off the book, OpenGL Game Programming and a few of these may now be incorrect as new DirectX versions are released. If you wish to correct me, please do via one of the ways listed at the end of this tutorial

我就是真命天子,顺我者生,逆我者死!
2009-08-23 17:42
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
我最喜欢的算法题目就是这道了   可是没人参与讨论

我就是真命天子,顺我者生,逆我者死!
2009-08-24 09:30
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
程序代码:
for (i = 0; a[i] == b[i]; i++)  
  if (a[i] == 0)     
   return 0;
return a[i] - b[i]; 

我就是真命天子,顺我者生,逆我者死!
2009-08-24 21:17
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
#include <stdio.h>
#include <string.h>
int main(void)
{
    printf("%d", strcmp("1", "1234"));
    return 0;
}

我就是真命天子,顺我者生,逆我者死!
2009-08-24 21:26
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
我把题目标准化了
欢迎参与讨论  共同学习

我就是真命天子,顺我者生,逆我者死!
2009-08-24 22:01
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
#include <stdio.h>
#include <string.h>

#define N 10010
#define M 10007
struct hashtabel
{
   
    char str[200] ;
    int num;
}a[N], b[N];

int hash(char *s)

{

    int h = 0, a = 127;
   
    for (; *s ; s++)
        
        h = (a*h + *s) % M;
   
    return h;
   
}

int getnum(char *s)
{
    int x;
   
    x = hash(s);
   
    while (strcmp(a[x].str, "") && strcmp(a[x].str, s)) // 该位置有值且值不匹配串
    {
        
        x = (x+1) % M;
        if (!(strcmp(a[x].str, "")))                    // 找一个没有值的位置
        {
            strcpy(a[x].str, s);
            return x;
        }
    }
    return x;
}

int main(void)
{
    char t[200];
    int i, j, n, total;
   
    for (i = 0; i < N; i++)
    {
        strcpy(a[i].str, "");
        a[i].num = 0;
    }
   
    scanf("%d\n", &n);
    for (i = 0, j = 0;  i < n; i++)
    {
        
        gets(t);
        total = getnum(t);
        
        if (a[total].num == 0)
        {
            strcpy(b[j].str, t);
            b[j].num = total;
            j++;
        }
        a[total].num++;
    }
   
    for (i = 0; i < j; i++)
        printf("%s %d\n", b[i].str, a[b[i].num].num);
   
    return 0;
}

我就是真命天子,顺我者生,逆我者死!
2009-08-25 12:53
快速回复:出个小题 活跃下论坛气氛
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017213 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved