【uva】10494 If We Were a Child Again

开始刷uva了,之前的十来道题都是比较轻松的,基本都是一遍过,这道WA了有7.8次。。。。。首先在本机测试过就花了好久,高精度除法和求模书上没讲,自己摸索比较慢。。。。。。然后就是求模的时候int有可能出现溢出,写的时候考虑到但是忘了修改,结果卡了好多次,还数次吧数组改大,真是郁闷。。。。

最后的代码写得很难看啊

Problem B
List of Conquests
Input:
standardinput
Output:
standard output
Time Limit:
2 seconds

In Act I, Leporello is tellingDonna Elvira about his master's long list of conquests:

``This is the list of the beauties my master has loved,a list I've made out myself: take a look, read it with me. In Italy six hundredand forty, in Germany two hundred and thirty-one, a hundred in France,ninety-one in Turkey; but in Spain already a thousand and three! Among them arecountry girls, waiting-maids, city beauties; there are countesses, baronesses,marchionesses, princesses: women of every rank, of every size, of every age.''(Madamina, il catalogo è questo)

AsLeporello records all the ``beauties'' Don Giovanni ``loved'' in chronological order,it is very troublesome for him to present his master's conquest to othersbecause he needs to count the number of ``beauties'' by their nationality eachtime. You are to help Leporello to count.

Input

Theinput consists of at most 2000lines, but the first. The first line contains a number n, indicating that there will be nmore lines. Each following line, with at most 75 characters, contains a country (the first word) and the name ofa woman (the rest of the words in the line) Giovanni loved. You may assume thatthe name of all countries consist of only one word.

Output

Theoutput consists of lines in alphabetical order. Each line starts with the nameof a country, followed by the total number of women Giovanni loved in thatcountry, separated by a space.

Sample Input

3
Spain Donna Elvira
England Jane Doe
Spain Donna Anna

Sample Output

England 1

Spain 2

#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<ctime>
#include<cctype>
#include<memory>
#include<cstdlib>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
const int N=1000000;
string a;
int b[N];
char c[20];
int num[N];
int main()
{
   while(getline(cin,a))
   {
       ll i=0;
       while(isdigit(a[i]))
       {
           b[i]=a[i]-'0';
           i++;
       }
       ll lenb=i-1;
  
       while(' '==a[i])
       i++;
       char cc=a[i];
       i++;
       while(' '==a[i])
        i++;
        ll k=0;
       while('\0'!=a[i])
       {
           c[k]=a[i];
           k++;
           i++;
       }
       c[k]='\0';
       ll d=atoi(c);
    
       if('%'==cc)
       {
          
           ll xx=1;
           ll mod=0;
           for(ll j=lenb;j>=0;j--)
           {
               mod=((b[j])*xx+mod)%d;
               xx=(xx*10)%d;
         
           }
           cout<<mod<<endl;
       }
       else if('/'==cc)
       {
           memset(num,0,sizeof(num));
           ll temp=0;
           for(int j=0;j<=lenb;j++)
           {

                        temp=temp*10+b[j];
                        num[j]=temp/d;
                        if((temp/d)){
                        temp=temp%d;}

           }
           int j=0;
           while(0==num[j]&&j<=lenb)
            j++;
            if(j>lenb)
                cout<<0;
            else
           for(;j<=lenb;j++)
           {
               cout<<num[j];
           }
           cout<<endl;
       }
   }
   return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值