|
|
back to boardwhat's wrong! How caan help me? #include<iostream> #include<string.h> using namespace std; int main() { char s[1000]; long l=0; cin.getline(s, sizeof(s)); for(int i=1; i<=strlen(s); i++) switch (s[i]) { case 'a':l++; break; case 'd':l++; break; case 'g':l++; break; case 'j':l++; break; case 'm':l++; break; case 'p':l++; break; case 's':l++; break; case 'v':l++; break; case 'y':l++; break; case '.':l++; break; case 'b':l+=2; break; case 'e':l+=2; break; case 'h':l+=2; break; case 'k':l+=2; break; case 'n':l+=2; break; case 'q':l+=2; break; case 't':l+=2; break; case 'w':l+=2; break; case 'z':l+=2; break; case ',':l+=2; break; case ' ':l++; break; case 'c':l+=3; break; case 'f':l+=3; break; case 'i':l+=3; break; case 'l':l+=3; break; case 'o':l+=3; break; case 'r':l+=3; break; case 'u':l+=3; break; case 'x':l+=3; break; case '!':l+=3; break; default: l++; } cout << l; } Re: what's wrong! How caan help me? char s[1000]; - change it on 1001 ( /0 is symbol ) Re: what's wrong! How caan help me? Posted by ELDVN 1 Nov 2015 02:31 #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std;
string s; int sum; main(){ getline(cin,s); for(int i=0; i < s.len; i++){ switch(s[i]){ case 'a':case'd':case 'g':case 'j':case 'm':case 'p':case 's':case 'v':case 'y':case '.':case ' ':sum+=1; break; case 'b':case'e':case 'h':case 'k':case 'n':case 'q':case 't':case 'w':case 'z':case ',':sum+=2; break; case 'c':case'f':case 'i':case 'l':case 'o':case 'r':case 'u':case 'x':case '!':sum+=3; break; } } printf("%d",sum);
return 0; } |
|
|