| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 492 人关注过本帖
标题:C++翻译为C
只看楼主 加入收藏
hcl1008
Rank: 1
等 级:新手上路
帖 子:18
专家分:9
注 册:2011-12-8
结帖率:71.43%
收藏
已结贴  问题点数:20 回复次数:2 
C++翻译为C
#include <stdio.h>
#include <string.h>
int main()
{
    char str1[100],str2[100];
    int n,t=0,i,j;
    gets(str1);
    gets(str2);
    n=strlen(str1);
    for(i=0;i<n-1;i++)
    {
        for(j=1;j<n;j++)
        {
            if(str2[j]==str1[i])
            {
                if(str1[i-1]==str2[j+1])
                {
                    t++;
                }
            }
        }
    }
    printf("%d",2*t);
    return 0;
}
求大神翻译翻译这个代码,并看看有没有错。。谢谢哦。。
搜索更多相关主题的帖子: 翻译 include 
2012-04-12 20:22
hcl1008
Rank: 1
等 级:新手上路
帖 子:18
专家分:9
注 册:2011-12-8
收藏
得分:0 
不好意思,我犯脑残了。。。代码黏贴错了。。。。是下面这个

#include<iostream.h>
#include<math.h>
#include<string>
using namespace std;
int main()
{
    string pre,lat;
    while(cin>>pre>>lat)
    {
        int count=1;
        int sum=0;
        for(int i=0;i<pre.length()-1;i++)
        {
            char c0 = pre[i];
            char c1 = pre[i+1];
            int index = lat.find(c0);
            if((index-1)>=0)
            {
                char c2 = lat[index-1];
                if(c1 == c2) count=count*2; }
}
        cout<<count;
 }
    return 0;
}
莫怪莫怪啊。。
2012-04-12 20:25
ming_wl
Rank: 2
等 级:论坛游民
帖 子:6
专家分:28
注 册:2012-4-9
收藏
得分:20 
应该是这样:
比如 有两个字符串 aaabb  abvc  count=2的3次方
也就是计算出pre中的连续字符的两两组合的个数为n(比如aaabb 中n=3,),那么count=2的n次方,而且字符必须在lat中存在
2012-04-12 20:53
快速回复:C++翻译为C
数据加载中...
 
   



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

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