zoukankan      html  css  js  c++  java
  • C++-HDU1000,1001,1002-格式是真的坑

    1 #include <cstdio>
    2 int main(){
    3     for(int a,b;~scanf("%d%d",&a,&b);printf("%d
    ",a+b));
    4     return 0;
    5 }
    hdu1000
    1 #include <cstdio>
    2 int main(){
    3     for(int n;scanf("%d",&n)!=EOF;printf("%d
    
    ",(n%2==0?((n/2)*(1+n)):((1+n)/2)*n)));
    4     return 0;
    5 }
    hdu1001
     1 #include <cmath>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 int main() {
     7     char s1[1000],s2[1000],s3[1001];
     8     int num1[1000],num2[1000],num3[1001],t,T;
     9     for(scanf("%d",&T),t=1; t<=T; t++) {
    10         scanf("%s%s",s1,s2);
    11         memset(num1,0,sizeof(num1));
    12         memset(num2,0,sizeof(num2));
    13         memset(num3,0,sizeof(num3));
    14         memset(s3,0,sizeof(s3));
    15         int len1=strlen(s1),len2=strlen(s2),len3=max(len1,len2);
    16         for(int i=len1-1,cnt=0;i>=0;num1[cnt++]=s1[i]-'0',i--);
    17         for(int i=len2-1,cnt=0;i>=0;num2[cnt++]=s2[i]-'0',i--);
    18         for(int i=0;i<len3;i++)num3[i]=num1[i]+num2[i];
    19         for(int i=0;i<len3;i++)if(num3[i]>9)num3[i+1]++,num3[i]%=10;
    20         if(num3[len3])len3++;
    21         for(int i=len3-1,cnt=0; i>=0; i--) s3[cnt++]=num3[i]+'0';
    22         printf("Case %d:
    %s + %s = %s
    ",t,s1,s2,s3);
    23         if(t!=T)printf("
    ");
    24     }
    25     return 0;
    26 }
    hdu1002
    ~~Jason_liu O(∩_∩)O
  • 相关阅读:
    Go
    Go
    Go
    Go
    Go
    Go
    爬虫常用相关库
    Go
    python基础第7天(day19)
    python基础第五天(day17)元组,集合,字符串操作 字符编码:
  • 原文地址:https://www.cnblogs.com/JasonCow/p/12276177.html
Copyright © 2011-2022 走看看