| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 731 人关注过本帖
标题:求大神改代码,acm的题,提交时报错怎么改,菜鸟一个
取消只看楼主 加入收藏
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:6 
求大神改代码,acm的题,提交时报错怎么改,菜鸟一个
1515377.cpp: 在函数‘int main()’中:
1515377.cpp:13:19: 错误:‘strlen’在此作用域中尚未声明

下边是代码
天大acm第4003题
源码
#include <iostream>
#include <stdio.h>
#define N 100005  
using namespace std;
char x[N];
int num[N];
int main() {
    int t,sum,ans,i;
    scanf("%d",&t);
    while(t--){
        sum=0;
        scanf("%s",x);
        int len=strlen(x);
        for(i=0;i<len;i++){
            num[i]=x[i]-'0';
            sum+=num[i];
        }
        ans=sum%10;
        bool bn=true;
        for(i=0;i<len;i++){
            if(num[i]!=9){
                bn=false;
            }
        }
        int gh=len-1;
        if(len-1==0){
            num[len-1]=10;
            bn=false;
        }
        if(bn==true){   
            num[gh]=9;
            num[0]=10;
            for(i=1;i<len-1;i++){
                num[i]=0;
            }
        }
        if(bn==false){
            if(num[len-1]+10-ans>=10){
                int bit=0;
                bool f=true;
                int u=len-1;
                if(len-1==0){
                    num[len-1]=19;
                    f=false;
                }
                bool hu=true;
                while(f){
                    if(hu){                        
                        if(num[u-1]+1==10){                    
                            bit++;
                        }else{                    
                            sum=sum-num[len-1]+1;               
                            int lk=10-sum%10;
                            num[len-1]=lk;
                            num[u-1]+=1;
                            f=false;
                        }
                        u=u-1;
                        ans=1;
                        hu=false;
                    }else{        
                        if(num[u]+1==10){                        
                            bit++;
                            num[u]=0;
                            u--;
                            ans=1;
                        }else{                    
                            num[u]=num[u]+1;                        
                            sum=sum-(bit-1)*9+1-num[len-1];                        
                            int jh=sum%10;
                            num[len-1]=10-jh;
                            f=false;
                        }                    
                    }

                }

            }else{
                num[len-1] +=10-ans;

            }
        }
        for(int i=0;i<len;i++)  
            printf("%d",num[i]);

        printf("\n");
    }
    system("pause");
    return 0;
}
搜索更多相关主题的帖子: include 
2015-04-08 22:11
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
回复 2楼 wyw19880809
不行呀
2015-04-08 23:08
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
加string.h
2015-04-08 23:11
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
回复 6楼 wmf2014
天大acm 第4003题,答案有错,提交了的,估计那儿出了问题
2015-04-08 23:18
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
The I-number of x is defined to be an integer y, which satisfied the the conditions below:

1. y>x;

2. the sum of each digit of y(under base 10) is the multiple of 10;

3. among all integers that satisfy the two conditions above, y shouble be the minimum.

Given x, you're required to calculate the I-number of x.

Input
An integer T(T≤100) will exist in the first line of input, indicating the number of test cases.

The following T lines describe all the queries, each with a positive integer x. The length of x will not exceed 105.

Output
Output the I-number of x for each query.

Sample Input

1
202



Sample Output

208
2015-04-08 23:19
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
回复 10楼 wp231957
感谢各位了,我解决了,不过换了一个方法,代码如下

#include <iostream>
#include <stdio.h>
#include <string.h>
#define N 100005  
using namespace std;
char x[N];
int num[N];
int dum[N];
int solve(int length,int k){
//        printf("k==  %d;length== %d\n",k,length );

    int sum=0;
    num[length]+=k;
    for(int i=length;i>=0;i--){
        if(num[i]>9){
            num[i-1]++;
        }

    }

    for(int j=0;j<=length;j++){
        //            printf("aaalength== %d\n",sum);
        if(j==0){
            if(num[j]==10){
                sum+=1;
            }else{
                sum+=num[j];
            }
        }else{
            sum+=num[j]%10;
            num[j]=num[j]%10;
        }
        

//            printf("sum== %d\n",sum);
//            printf("num[%d]==  %d\n",j,num[j] );
    }
    return sum%10;
}
int main() {
    int t,sum,ans,i;
    scanf("%d",&t);
    while(t--){
        sum=0;
        scanf("%s",x);
        int len=strlen(x);
        for(i=0;i<len;i++){
            num[i]=x[i]-'0';
            dum[i]=x[i]-'0';
            sum+=num[i];
        }
        ans=sum%10;
        int j=num[len-1];
        if(len==1){
            printf("%d",19);

        }else{

            for(i=1;i<20;i++){
                if(solve(len-1,i)==0){
                    for(int j=0;j<len;j++){
                        printf("%d",num[j]);
                    }
               
                    break;
                }else{

                    for(int j=0;j<len;j++){
                        num[j]=dum[j];
                    }
                }

            }
        }
            printf("\n");
    }
//    system("pause");
    return 0;
}
2015-04-09 11:36
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
回复 10楼 wp231957
调试时用的,提交时去了的
2015-04-09 11:37
快速回复:求大神改代码,acm的题,提交时报错怎么改,菜鸟一个
数据加载中...
 
   



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

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