Beer Bill(签到题)

在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
题意:输入两种字符串:
一种是全为|:那么值就位42*|的个数;
另一种是开始是整数,后面是|:当开头为整数,后面没有|的时候此时值就为开头的整数,否则值就为开头的整数*同一行后面的|的个数;
所以这是一个阅读题;
AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main(){
    
    
	ifstream in("data.txt");
   ll ans=0;
    ll i=0;
    while(cin>>s){
    
    
   	  if(s[0]=='|'){
    
    
   	  	    ans+=s.length()*42;
		 }else{
    
    
		    ll t=0,num=0;
		    for(int j=0;j<s.length();j++){
    
    
		    	   if(s[j]<='9'&&s[j]>='0'){
    
    
		    	   	  t=t*10+s[j]-'0';
				   }else if(s[j]=='|'){
    
    
				   	 num++;
				   }
			}
			ans+=t*num;
		 }
   }
   if(ans%10)ans=ans-ans%10+10;//注意最后向上取整
   printf("%lld,-\n",ans);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44555205/article/details/104451064