著名科學家盧斯爲了檢查學生對進位制的理解,他給出了以下的一張加法表,表中的字母表明數字。 例如:ios
L L K V Eide
K K V E KLspa
V V E KL KKcode
E E KL KK KVblog
其含義爲:ip
L+L=L,L+K=K,L+V=V,L+E=Eci
K+L=K,K+K=V,K+V=E,K+E=KL字符串
…… E+E=KVget
根據這些規則可推導出:L=0,K=1,V=2,E=3string
同時能夠肯定該表表示的是4進制加法
//感謝lxylxy123456同窗爲本題新加一組數據
輸入格式:
n(n≤9)表示行數。
如下n行,每行包括n個字符串,每一個字串間用空格隔開。(字串僅有一個爲‘+’號,其它都由大寫字母組成)
輸出格式:
① 各個字母表示什麼數,格式如:L=0,K=1,……按給出的字母順序。
② 加法運算是幾進制的。
③ 若不可能組成加法表,則應輸出「ERROR!」
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
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 }