noip 1998 洛谷P1013 进制位

题目描述

著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字。 例如:

  • L K V E

L L K V E

K K V E KL

V V E KL KK

E E KL KK KV

其含义为:

L+L=L,L+K=K,L+V=V,L+E=E

K+L=K,K+K=V,K+V=E,K+E=KL

…… E+E=KV

根据这些规则可推导出:L=0,K=1,V=2,E=3

同时可以确定该表表示的是4进制加法

//感谢lxylxy123456同学为本题新加一组数据

输入输出格式

输入格式:

 

n(n≤9)表示行数。

以下n行,每行包括n个字符串,每个字串间用空格隔开。(字串仅有一个为‘+’号,其它都由大写字母组成)

 

输出格式:

 

① 各个字母表示什么数,格式如:L=0,K=1,……按给出的字母顺序。

② 加法运算是几进制的。

③ 若不可能组成加法表,则应输出“ERROR!”

 

输入输出样例

输入样例#1:
5
+ L K V E
L L K V E
K K V E KL
V V E KL KK
E E KL KK KV
输出样例#1:
L=0 K=1 V=2 E=3
4
————————————————————————————————————————————我是分割线————————————————————————————————————————

用样例来举例:

5 + L K V E

L L K V E

K K V E KL

V V E KL KK

E E KL KK KV

其中没有标粗的部分字母有几个这个字母就代表那个数-1

还有一点,两个及两个以上的数字忽略

如:L

L只出现了一次(自己数),所以代表0

K出现了两次,所以代表1

……

记得要判断是否能组成加法表。

 1 /*
 2     Problem:
 3     OJ:
 4     User:    S.B.S.
 5     Time:
 6     Memory:
 7     Length:
 8 */
 9 #include<iostream>
10 #include<cstdio>
11 #include<cstring>
12 #include<cmath>
13 #include<algorithm>
14 #include<queue>
15 #include<cstdlib>
16 #include<iomanip>
17 #include<cassert>
18 #include<climits>
19 #include<functional>
20 #include<bitset>
21 #include<vector>
22 #include<list>
23 #define F(i,j,k) for(int i=j;i<k;++i)
24 #define M(a,b) memset(a,b,sizeof(a))
25 #define FF(i,j,k) for(int i=j;i>=k;i--)
26 #define maxn 101
27 #define inf 0x3f3f3f3f
28 #define maxm 4001
29 #define mod 998244353
30 //#define LOCAL
31 using namespace std;
32 int read(){
33     int x=0,f=1;char ch=getchar();
34     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
35     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
36     return x*f;
37 }
38 int n,m;
39 int cnt[maxn];
40 int temp[maxn];
41 char data[10];
42 int main(int argc,const char *argv)
43 {
44 //    std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
45     #ifdef LOCAL
46     freopen("data.in","r",stdin);
47     freopen("data.out","w",stdout);
48     #endif
49     cin>>n;getchar();n--;
50     F(i,0,n){
51         char str;
52         getchar();cin>>str;data[i]=str;
53     }
54     F(i,0,n){
55         getchar();char ch;cin>>ch;
56         F(j,0,n){
57             getchar();string str;cin>>str;
58             if(str.size()==1){
59                 F(k,0,n){
60                     if(data[k]==str[0]){
61                         cnt[k]++;
62                         break;
63                     }
64                 }
65             }
66         }
67     }
68     F(i,0,n) if(cnt[i]-1==-1){cout<<"ERROR!"<<endl;return 0;}
69     F(i,0,n) cout<<data[i]<<"="<<cnt[i]-1<<" ";
70     cout<<endl<<n<<endl;
71     return 0;
72 }
p1013

 

posted @ 2016-10-24 19:46  SBSOI  阅读(684)  评论(0编辑  收藏  举报