2009-04-04 13:54:23來源不明

Stringstream運用練習(C++)

/***********************************/

#include<stdio.h>  
#include<stdlib.h>
#include<string.h>
main()
{
 char x[1000];
 long long int ans;
 int a,b,c,temp,flag;
 while(gets(x))
  {     temp=0;ans=0;flag=0;
   for(a=0;a<strlen(x);a++)
    {
    if(x[a]<=57&&x[a]>=48&&flag==0)
     temp=temp*10+x[a]-48;
    else if(x[a]==' ')
     {ans=ans+temp;temp=0;flag=0;}
    else
     {temp=0;flag=1;} 
    }  
    if(temp!=0)
     ans=ans+temp;
     printf("%lld\n",ans);
  }  
 return 0;    
}

上一篇:態度之重要的證明

下一篇:最小公倍數

terry0412 2009-05-17 01:58:07

請求出所有僅含數字的單字,並且加總後輸出。這些數字的總和不會超過2的16次方。

題目說總何不超過2的16次方

那為何宣告變數型態要用 long long int = =?

版主回應
那個時候的我還很弱
不要問
2009-05-17 07:11:11