模拟

最简单的计算机

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2907    Accepted Submission(s): 1675


Problem Description
一个名叫是PigHeadThree的研究组织设计了一台实验用的计算机,命名为PpMm。PpMm只能执行简单的六种命令A,B,C,D,E,F;只有二个内存M1,M2;三个寄存器R1,R2,R3。六种命令的含义如下:
  命令A:将内存M1的数据装到寄存器R1中;
  命令B:将内存M2的数据装到寄存器R2中;
  命令C:将寄存器R3的数据装到内存M1中;
  命令D:将寄存器R3的数据装到内存M2中;
  命令E:将寄存器R1中的数据和寄存器R2中的数据相加,结果放到寄存器R3中;
  命令F:将寄存器R1中的数据和寄存器R2中的数据相减,结果放到寄存器R3中。
你的任务是:设计一个程序模拟PpMm的运行。
 

Input
有若干组,每组有2行,第一行是2个整数,分别表示M1和M2中的初始内容;第二行是一串长度不超过200的由大写字母A到F组成的命令串,命令串的含义如上所述。
 

Output
对应每一组的输入,输出只有一行,二个整数,分别表示M1,M2的内容;其中M1和M2之间用逗号隔开。

其他说明:R1,R2,R3的初始值为0,所有中间结果都在-2^31和2^31之间。
 

Sample Input
100 288 ABECED 876356 321456 ABECAEDBECAF
 

Sample Output
388,388 2717080,1519268
AC代码:
#include<stdio.h>
#include<string.h>
int main()
{
 int a,b,m,n,p,i,a1,b1;
 char s[500];
 while(scanf("%d%d",&a,&b)!=EOF)
 {
  getchar();
  scanf("%s",s);
  a1=a;
  b1=b;
  m=n=p=0;
        for(i=0;i<strlen(s);i++)
  {
            if(s[i]=='A')  m=a1;
   else if(s[i]=='B') n=b1;
      else if(s[i]=='C') a1=p;
   else if(s[i]=='D')  b1=p;
   else if(s[i]=='E')  p=m+n;
   else if(s[i]=='F')  p=m-n;
  }
  printf("%d,%d\n",a1,b1);
 }
 return 0;
}

水果

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1599    Accepted Submission(s): 634


Problem Description
夏天来了~~好开心啊,呵呵,好多好多水果~~
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了.
 

Input
第一行正整数N(0<N<=10)表示有N组测试数据.
每组测试数据的第一行是一个整数M(0<M<=100),表示工有M次成功的交易.其后有M行数据,每行表示一次交易,由水果名称(小写字母组成,长度不超过80),水果产地(小写字母组成,长度不超过80)和交易的水果数目(正整数,不超过100)组成.
 

Output
对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序.
两组测试数据之间有一个空行.最后一组测试数据之后没有空行.
 

Sample Input
1 5 apple shandong 3 pineapple guangdong 1 sugarcane guangdong 1 pineapple guangdong 3 pineapple guangdong 1
 

Sample Output
guangdong |----pineapple(5) |----sugarcane(1) shandong |----apple(3)
 AC代码:
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
 string a,b;
 map<string,map<string,int> >mp;
     int t,i,n,num;
     cin>>t;
  while(t--)
  {
   cin>>n;
   mp.clear();
         for(i=0;i<n;i++)
   {
    cin>>a>>b>>num;
    (mp[b])[a]+=num;
   }
   map<string,map<string,int> >::iterator it;
   map<string,int>::iterator is;
   for(it=mp.begin();it!=mp.end();it++)
   {
    cout<<it->first<<endl;
    for(is=it->second.begin();is!=it->second.end();is++)
    {
     cout<<"   |----"<<is->first<<"("<<is->second<<")"<<endl;
    }
   }
   if(t)  cout<<endl;
  }
 return 0;
}

LC-Display

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 798    Accepted Submission(s): 322


Problem Description
A friend of you has just bought a new computer. Until now, the most powerful computer he ever used has been a pocket calculator. Now, looking at his new computer, he is a bit disappointed, because he liked the LC-display of his calculator so much. So you decide to write a program that displays numbers in an LC-display-like style on his computer.
 

Input
The input contains several lines, one for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99 999 999), where n is the number to be displayed and s is the size in which it shall be displayed.

The input file will be terminated by a line containing two zeros. This line should not be processed.
 

Output
Output the numbers given in the input file in an LC-display-style using s ``-'' signs for the horizontal segments and s ``|'' signs for the vertical ones. Each digit occupies exactly s+2 columns and 2s+3 rows. (Be sure to fill all the white space occupied by the digits with blanks, also for the last digit.) There has to be exactly one column of blanks between two digits.

Output a blank line after each number. (You will find a sample of each digit in the sample output.)
 

Sample Input
2 12345 3 67890 0 0
 

Sample Output
-- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- ---
AC代码:
#include<iostream>
#include<string>
using namespace std;
char p[5][31]={
 {" -     -  -     -  -  -  -  - "},
 {"| |  |  |  || ||  |    || || |"},
 {"       -  -  -  -  -     -  - "},
 {"| |  ||    |  |  || |  || |  |"},
 {" -     -  -     -  -     -  - "},
};
void output(int time,string s,int i)
{
int len=s.length()-1,j,k;
for(j=0;j<=len;j++)
{
 int m=(s[j]-'0')*3;
 cout<<p[i][m];
 for(k=0;k<time;k++)
 {
  cout<<p[i][m+1];
 }
 cout<<p[i][m+2];
 if(j!=len)  cout<<" ";
}
cout<<endl;
}
int main()
{
int n,i,j;
string s;
while(cin>>n>>s)
{
 if(n==0&&s=="0")  break;
    for(i=0;i<5;i++)
 {
  if(i&1)
  {
          for(j=0;j<n;j++)
     output(n,s,i);
  }
  else output(n,s,i);
 }
 cout<<endl;
}
 return 0;
}
posted @ 2012-10-23 19:03  forevermemory  阅读(215)  评论(0编辑  收藏  举报