POJ 1750 Dictionary

【题意简述】:我想根据输入输出,就差不多能搞懂题意了,我就不再描述

【分析】:最不喜欢字符串的问题,唉,见代码吧,处理的方法都在代码中。注意此题一直都是相邻的两个字符串相比就对了,抓住这一点,就可以很简单的解决。

详见代码:

//196K  1000Ms
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

char str1[100],str2[100];

int main()
{
    int SameNum = 0,spaceNum = 0;//相同的字符数,还有空格数
    int i;
    cin>>str1;
    cout<<str1<<endl;
    while(cin>>str2)
    {
        for(i = 0;i<strlen(str1),i<strlen(str2);i++)
            if(str1[i] != str2[i])
                break;
        if(i>SameNum)
            spaceNum++;
        else
            spaceNum = i;

        SameNum=spaceNum;

        for(i = 0;i<spaceNum;i++)
            putchar(" ");
        cout<<str2<<endl;
        strcpy(str1,str2);
    }
    return 0;
}
时间: 2024-08-15 04:05:33

POJ 1750 Dictionary的相关文章

POJ 1750 Dictionary(模拟)

题目链接:http://poj.org/problem?id=1750 Description Authors of the new, all-in-one encyclopedia have organized the titles in the order they consider most appropriate for their readers. It's not always alphabetical, because they want to observe some pecul

poj 1750 java

这道题很坑爹,稍微不注意不是PE就是RA要么TLE. 先说下题意: 题干描述的不是很清晰,主要是通过题目给的例子自己总结的,(这个很关键,没找着好的规律永远会TLE): 规律:后面一个字符串和前面一个字符串比较,如果前几位相同的字符数量大于空格的数量,那么空格的数量加1,如果前几位相同字符数量小于空格的数量,那么空格数量变为相同字符的数量. 网上用java实现的代码基本没找着,没办法,之前poj上一共就4位前辈用java Ac的,只能自己动手了, 开始我直接暴力比较直接打印,最后把RA解决了,但

POJ 1035 Spell checker

题目链接 http://poj.org/problem?id=1035 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24142   Accepted: 8794 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the cor

POJ 2503 Babelfish (Trie树 或 map)

Babelfish Time Limit: 3000MS        Memory Limit: 65536K Total Submissions: 34278        Accepted: 14706 Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately

POJ 2337 Catenyms (有向图欧拉通路)

Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9914   Accepted: 2588 Description A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For e

POJ 3449 Geometric Shapes --计算几何,线段相交

题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一步来吧. 还有收集了一个线段旋转的函数. Vector Rotate(Point P,Vector A,double rad){ //以P为基准点把向量A旋转rad return Vector(P.x+A.x*cos(rad)-A.y*sin(rad),P.y+A.x*sin(rad)+A.y*co

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京